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
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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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