I have a mysql query:
$result = mysql_query("my query");
Is there a way to make something like this work?
$results = mysql_fetch_assoc($result); // fetch the results
And loop them using foreach instead of the classic while:
foreach($results as $result){
$result1 = $result->result1;
$result2 = $result->result2;
}
Ty
Foreach is a construct that iterates arrays and objects. mysql_fetch_assoc
will return an array but each array will be only one row's worth of data. So your foreach will simply be giving you the columns present in the first row.
Save yourself from trouble, don't use mysql_fetch_assoc and foreach together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With