Jump to content

[SOLVED] WHERE won't select the correct records


jeff5656

Recommended Posts

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.