TobesC Posted January 8, 2008 Share Posted January 8, 2008 Im trying to write a script to echo different lines based on the value of a result but whenever i run it, all of the variables are true all of the time. enclosed please find code - any explanation would be appreciated. thanks. date format Y-m-d, doc=2 start="0"(8:30),".25"(8:45),".5"(9:00),".75". . . <?php $result=mysql_query("SELECT * FROM `appt_list` WHERE `date`='$date' AND `doc`='$doc' AND `start`<='$start' AND `broken`='' ORDER BY `start` DESC "); $row=mysql_fetch_array($result); if ($row!="") { $pt=$row['pt']; $presult=mysql_query("SELECT * FROM `patient_list` WHERE `pt`='$pt'"); $prow=mysql_fetch_array($presult); $then=$row['start']; $length=$row['length']; if ($then==$start) { $aid=$row['aid']; $first="y"; $edit="y";} if (($length!=".25")AND($then+.25==$start)) {$desc="y"; $edit="y";} if (($then<=$start)AND($start<$then+$length)) {$edit="y"; } if ($start>=$then+$length) { $open="y"; } } if ($row=="") { $open="y"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/ Share on other sites More sharing options...
revraz Posted January 8, 2008 Share Posted January 8, 2008 print_r($row) and print_r($prow) to see if they contain what you expect. I'm thinking they don't. Are you only expecting 1 row of data to be returned? Quote Link to comment https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/#findComment-433754 Share on other sites More sharing options...
kenrbnsn Posted January 8, 2008 Share Posted January 8, 2008 The variable "$row" is an array and, as such, a test like " if ($row != "") " will not work. I believe you want to do something like: <?php $q = "SELECT * FROM `appt_list` WHERE `date`='$date' AND `doc`='$doc' AND `start`<='$start' AND `broken`='' ORDER BY `start` DESC "; $result=mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); if (mysql_num_rows($result) > 0) { $row=mysql_fetch_assoc($result); $pt=$row['pt']; $q2 = "SELECT * FROM `patient_list` WHERE `pt`='$pt'"; $presult=mysql_query($q2) or die("Problem with the query: $q2<br>" . mysql_error()); $prow=mysql_fetch_assoc($presult); $then=$row['start']; $length=$row['length']; if ($then==$start) { $aid=$row['aid']; $first="y"; $edit="y";} if (($length!=".25") && ($then+.25==$start)) { $desc="y"; $edit="y";} if (($then<=$start) && ($start<$then+$length)) $edit="y"; if ($start >= $then+$length) $open="y"; } else $open = "y"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/#findComment-433757 Share on other sites More sharing options...
TobesC Posted January 8, 2008 Author Share Posted January 8, 2008 thanks for the replies, but im not having a problem with testing $row - its just that for some reason $first, $edit and $open are all true all the time, even though $first can only be a single instance, and edit and open are mutually exclusive. thanks Quote Link to comment https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/#findComment-433772 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.