Tuesday, 28 August 2018

MySQL does not return all results from my InnoDB table?

I am trying to get hold of 1 record from a MySQL table using PHP. I have tried many different SELECT statements and had no luck so decided to ask PHP to show me ALL results for this certain column. It returned all results EXCEPT the first result.

Im guessing this is why when it finds the result i need from the SELECT statement it does find a value but for some reason doesn't give it to me?
Its probably really obvious but i accept defeat now, please help!
$query="SELECT cw_id FROM unihubUpcoming";
$result = mysql_query($query) or die(mysql_error());

if(!$result){
 die('Query Failed!');
}

$row = mysql_fetch_assoc($result);

while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
 echo $row[0];
}

All that code does is execute the $query and print all items out but the first result found.
Thank you guys!

// get the first result
$row = mysql_fetch_assoc($result);
// but don't do anything with it

// loop and display all subsequent results
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
 echo $row[0];
}

0 comments:

Post a Comment