3

I am trying to get my server to connect.. But I'm having some trouble.

So, I have this code:

$id = (int)$_GET["id"];

$temp = mysql_query("SELECT * FROM ForumThread WHERE ID = $id");
if (mysql_num_rows($temp) > 0) {
    $ThreadInfo = mysql_fetch_assoc($temp);
}
if ($ThreadInfo) {
    if (isset($_GET["p"])-1) {
        $page = $_GET["p"];
    } else {
        $page = 1;
    }
    $offset =( 8 * intval($page));
    if(!$offset){
        $offset = 0;
    }


$posttemp = mysql_query("SELECT * FROM ForumPost WHERE ThreadID = $id ORDER BY ID ASC LIMIT $offset, 9");

$numpost = mysql_query("SELECT COUNT(*) FROM ForumPost WHERE ThreadID = $id");
$numpostfin = mysql_result($numpost, 0);
$numpage = ceil($numpostfin / 8);

$ThreadPost = mysql_fetch_assoc($posttemp);
}

But when I try this out on my site, it's skipping the first row. Just the first.

So I have this test in my database, and it won't where I have:

(I am not allowed to post pictures, because I don't have a reputation of 10)

My database - Don't mind the danish

And its skipping the first that it reads?

Please excuse my English :)

Asger Weirsøe
  • 350
  • 1
  • 11
  • 10
    **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). **Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and **use [PDO](http://us1.php.net/pdo).** – Jay Blanchard Jan 21 '15 at 14:13
  • What's the value of $page (are you starting at page 0 or page 1?) – Matt McDonald Jan 21 '15 at 14:14
  • `if (isset($_GET["p"])-1) {` ?!? If `isset($_GET["p"])` is TRUE, this will then execute `TRUE - 1` (giving `0` after type-juggling) which will be treated as a FALSE for the `if` statement – Mark Baker Jan 21 '15 at 14:15
  • 1
    The first call to `mysql_result()` advances the record pointer, which is why it appears to skip a row later. – Michael Berkowski Jan 21 '15 at 14:16
  • are there any errors on display? use `error_reporting(E_ALL);` – Giwwel Jan 21 '15 at 14:17
  • what does (int)$_GET['id']? – Top Questions Jan 21 '15 at 14:19
  • @TopQuestions It casts the input `?id=` to an integer, which would be numeric if it was a numeric value or zero if it was not numeric. – Michael Berkowski Jan 21 '15 at 14:20
  • If you must call `mysql_result()` in that place, you would then need to rewind it after with `mysql_data_seek($numpost, 0)` – Michael Berkowski Jan 21 '15 at 14:22
  • @MichaelBerkowski Thanks. Haven't seen it that way anywhere before...I used to check if(ctype_digit($_GET['id'])) and then escape it... – Top Questions Jan 21 '15 at 14:25

0 Answers0