jeff5656 Posted September 20, 2009 Share Posted September 20, 2009 This is weird. I select from this database and run a while loop: <?php if(isset($_POST['so'])) { $_SESSION['so'] = $_POST['so']; $so = $_POST['so']; } elseif (isset($_SESSION['so'])) { $so = $_SESSION['so']; } else { $so = 'a'; } ...snip.... $query = "SELECT * FROM active_consults WHERE signoff_status = '$so' ". "ORDER BY rcf_date2 DESC"; $results = mysql_query ($query) or die (mysql_error()); while ($row = mysql_fetch_assoc ($results)) { Later in the code, inside this while loop I do this: $count=0; $query2 = "SELECT * FROM active_consults WHERE signoff_status = 's' "; $results2 = mysql_query ($query) or die (mysql_error()); while ($signoff = mysql_fetch_assoc ($results2)) { echo $signoff['patient_name']; echo $signoff['mrn'] ." "; echo $signoff['signoff_status']."<br>"; if ($signoff['mrn']==$row['mrn']){ echo "match!<br>"; $count++; } } if ($count>0){ echo $count." previous consult";if ($count>1){echo"s";} } But the records from $signoff are ONLY signoff_status= 'a' even though I specifically said WHERE signoff_status = 's'. Why is it not selecting the correct records that match signoff_status "s" in that second query? Is it because I can't query the same table inside a while loop until that loop is done? Just a guess.. Link to comment https://forums.phpfreaks.com/topic/174913-solved-where-wont-select-the-correct-records/ Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 Read this $query2 = "SELECT * FROM active_consults WHERE signoff_status = 's' "; $results2 = mysql_query ($query) or die (mysql_error()); dose it really look right ? look 2 times hit: use the variables you set Link to comment https://forums.phpfreaks.com/topic/174913-solved-where-wont-select-the-correct-records/#findComment-921782 Share on other sites More sharing options...
jeff5656 Posted September 20, 2009 Author Share Posted September 20, 2009 aha!! thank you :-) How the heck do you guys pick up on these things so quickly. Link to comment https://forums.phpfreaks.com/topic/174913-solved-where-wont-select-the-correct-records/#findComment-921784 Share on other sites More sharing options...
MadTechie Posted September 20, 2009 Share Posted September 20, 2009 We learn from our mistakes.. As you can see I have made a lots, if you output is wrong.. first step is check your input Link to comment https://forums.phpfreaks.com/topic/174913-solved-where-wont-select-the-correct-records/#findComment-921787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.