0

So I am having issues with the first row of the database being left out, not sure as to why yet. Here is the code in a nutshell, leaving out the connection part and such.

$tickets="tickets";
$sql_ticket="SELECT * FROM $tickets WHERE username='$user'";
$ticket_query=mysql_query($sql_ticket);
$ticket_data=mysql_fetch_assoc($ticket_query);
while($ticket_data=mysql_fetch_assoc($ticket_query)){
// echoing in tables
}
3
  • Just read the code, this is quite obvious.... If you don't see the error, make sure you understand what each line does. This will be a good exercise. Commented Dec 4, 2012 at 13:57
  • 1
    Please do not continue using mysql_-class functions. Either use mysqli_, MYSQLI::, or PDO. See php.net/manual/en/book.mysqli.php and php.net/manual/en/book.pdo.php Commented Dec 4, 2012 at 13:57
  • Every call to mysql_fecch_assoc() advances the record pointer one row. So when you enter your loop, it's already at the second row. Commented Dec 4, 2012 at 13:57

1 Answer 1

3

Remove this line:

$ticket_data=mysql_fetch_assoc($ticket_query);

as you are fetching 1st row outside of your loop. Corrected code should be:

$tickets="tickets";
$sql_ticket="SELECT * FROM $tickets WHERE username='$user'";
$ticket_query=mysql_query($sql_ticket);
while($ticket_data=mysql_fetch_assoc($ticket_query)){
   // echoing in tables
}
Sign up to request clarification or add additional context in comments.

2 Comments

Ah right, so I already assigned the first line by doing this I suppose?
Exactly, that was your bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.