jeff5656 Posted August 20, 2009 Share Posted August 20, 2009 Below is a snippet where I pull a record from a table. I want to display this line echo "the record doesn't exist"; if the record doesn't exist. How do I do this? Also I'm not sure WHER i put this. It an't be inside the while loop since that's not run f the record doesn't exist. If I put it outside the while oop it gets displayed even if the record exists! <?php $consultsq3 = "SELECT * FROM icu INNER JOIN family ON icu.id_incr = family.pt_id AND icu.id_incr = ' " . $row['id_incr'] . " '"; $result3 = mysql_query ($consultsq3) or die ("Invalid query: " . mysql_error ()); while ($row3 = mysql_fetch_assoc ($result3)) { echo "the record doesn't exist"; if ($row3['family_date'] == $current_date) { ?><a href="newfamily.php?id=<?php echo $row['id_incr']; ?>"><img src="../consults/images/familycheck.jpg" alt="m&m" width="80" height="20" border="0" /> </a><?php } } ?> Link to comment https://forums.phpfreaks.com/topic/171184-check-if-a-record-exist-inside-or-before-a-while-loop/ Share on other sites More sharing options...
milesap Posted August 20, 2009 Share Posted August 20, 2009 I would change $result3 to: $result3 = mysql_fetch_assoc(mysql_query($consultsq3)); if (empty($result3)) { echo 'No record found!'; } else { foreach ($result3 as $index => $value) { // something goes here } } Link to comment https://forums.phpfreaks.com/topic/171184-check-if-a-record-exist-inside-or-before-a-while-loop/#findComment-902718 Share on other sites More sharing options...
jeff5656 Posted August 20, 2009 Author Share Posted August 20, 2009 I do not know ow to use foreaches that's why I have the While. I guess the empty solution doesn't work with my code? Ok, so if that's th case, how can I customize the foreac with my code? What is $index and $value? Do I still have to use $row['fieldname']? Link to comment https://forums.phpfreaks.com/topic/171184-check-if-a-record-exist-inside-or-before-a-while-loop/#findComment-902734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.