Jump to content

True all of the time


TobesC

Recommended Posts

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";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/85051-true-all-of-the-time/#findComment-433757
Share on other sites

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.