0

I have this array populating from mysql. But it is not showing me the first record. I can't figure out what the problem is. It should be simple. Here is the code.

$result=mysql_query("SELECT user_instance.instance_name, user_instance.host_name FROM       
dba_account, user_instance WHERE dba_account.account_id = user_instance.account_id AND 
dba_account.account_id = '1'");
echo mysql_error();
$nume = mysql_fetch_row($result);
while($note = mysql_fetch_array($result))
{
    echo "<tr>";
    echo "<td><input type='text' name='instance_name' class='instance_name'
    disabled='disabled' value='$note[instance_name]' size='25' /></td>";
    echo "<td><input type='text' name='host_name' class='host_name' disabled='disabled' 
    value='$note[host_name]' size='25' /></td>";
    echo "</tr>";
}
2
  • 2
    get rid of $nume = mysql_fetch_row($result); Commented Jul 17, 2012 at 18:58
  • Which array is causing problems? Commented Jul 17, 2012 at 19:00

2 Answers 2

6

You're fetching the first row in $nume = mysql_fetch_row. That pulls the first record. Then you're iterating through the rest of the records in your while loop. Remove that first line.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. But i just posted it so it's telling me to wait for 10 minutes. After that I will. Thanks
4

The first time you call mysql_fetch_row(), it advances the result resource pointer to the second result. Don't do that. Especially considering you are not using the variable $nume in your loop in any way, it is unnecessary and harmful to your logic.

// Don't do this!
//$nume = mysql_fetch_row($result);

// Instead just fetch the loop
while($note = mysql_fetch_array($result)) {
   // etc...
}

Comments

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.