jeff5656 Posted August 21, 2009 Share Posted August 21, 2009 Trying to get this to work but nothing gets displayed inside the if OR inside the else. I am not sure what is $index and what is $value. If index a field name that I selected, or is value a field name? <?php $consultsq3 = "SELECT * FROM icu INNER JOIN family ON icu.id_incr = family.pt_id AND icu.id_incr = ' " . $row['id_incr'] . " '"; $result3 = mysql_fetch_assoc(mysql_query($consultsq3)) or die ("Invalid query: " . mysql_error ()); if (empty($result3)) { echo 'No record found!'; } else { foreach ($result3 as $index => $value) { echo "index is " .$index . "and vakue is". $value; } Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/ Share on other sites More sharing options...
Adam Posted August 21, 2009 Share Posted August 21, 2009 try this: <?php $consultsq3 = mysql_query("SELECT * FROM icu INNER JOIN family ON icu.id_incr = family.pt_id AND icu.id_incr = ' " . $row['id_incr'] . " '") or die ("Invalid query: " . mysql_error ()); if (mysql_num_rows($consultsq3) == 0) { echo 'No record found!'; } else { $result3 = mysql_fetch_assoc($consultq3); foreach ($result3 as $index => $value) { echo "index is " .$index . "and vakue is". $value; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/#findComment-903319 Share on other sites More sharing options...
jeff5656 Posted August 21, 2009 Author Share Posted August 21, 2009 I did what you outlined and I get this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\mc\test.php on line 204 I think the problem is I have no idea what "$index" AND "VAlue" are supposed to be. Do both (or one) of them refer to a field name? If so which one? And then what does the other one represent? Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/#findComment-903328 Share on other sites More sharing options...
Adam Posted August 21, 2009 Share Posted August 21, 2009 Heh, can't believe I didn't spot this before. Have you connected? Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/#findComment-903330 Share on other sites More sharing options...
jeff5656 Posted August 21, 2009 Author Share Posted August 21, 2009 Yep I connect to dbase. I just didnt show that code above Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/#findComment-903332 Share on other sites More sharing options...
Adam Posted August 21, 2009 Share Posted August 21, 2009 Heh worth asking, some people do actually forget. I wrote the variable wrong for the mysql_fetch_assoc call, should be "$consultsq3". Quote Link to comment https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/#findComment-903333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.