Jump to content

[SOLVED] Echo Row If problem


savagenoob

Recommended Posts

OK, I am querying the database to pull the time and description from a table for just a certain day. I have a table setup that has time from 8 am to 6 pm on the left and the column next to it room for the event. I cant figure out how to show the event in the row that equals the time...

Here is the code, the way I have just displays all the events if there is one that equals 08:00.

<?php
$query1= "SELECT time, description FROM cal_events WHERE date = '$finaldate1' AND user_id = '$employee'";
				 $result1=mysql_query($query1);
				 while($row1=mysql_fetch_assoc($result1))
				 {

?>
<th scope="col">8:00am</th>
    <th height="48" scope="col"><?php if ($row1['time'] = "08:00") {echo $row1['description'];}?></th>

Link to comment
Share on other sites

OI, your problem stems from teh fact that your IF condition is SETTING the value insted of TESTING the value.

 

Wrong:

if ($row1['time'] = "08:00")

 

Right:

if ($row1['time'] == "08:00")

 

 

But, a better solution would be to add the 'time' column to your WHERE clause

 

<?php
$time = '8:00';

$query1= "SELECT time, description
          FROM cal_events
          WHERE date = '$finaldate1'
            AND user_id = '$employee'
            AND time = '$time'";

$result1=mysql_query($query1);
while($row1=mysql_fetch_assoc($result1))
{

?>
<th scope="col">8:00am</th>
    <th height="48" scope="col"><?php echo $row1['description']; ?></th>

Link to comment
Share on other sites

Kinda solved this... doesnt do it exactly but close enough  ;D

<?php

				$comma1 = ", ";
				$space1 = " ";
				$date1 =$month . $space1 . $day . $comma1 . $year;
				$nextdate1 = strtotime($date1);
$finaldate1 = date("Y-m-d", $nextdate1);
				$query1= "SELECT time, description FROM cal_events WHERE date = '$finaldate1' AND user_id = '$employee' ORDER BY time";
				 $result1=mysql_query($query1);
				 while($row1=mysql_fetch_assoc($result1))
				 {
					 $echotime = $row1['time'];
					 $nexttime = strtotime($echotime);
					 $newtime = date("g:ia", $nexttime);
					 $echodesc = $row1['description'];

?>
  <tr>
    <th scope="col"><?php echo $newtime; ?></th>
    <th height="48" scope="col"><?php echo $echodesc; ?></th>
  </tr>
  <tr>
  
<?php
			 }
			 }
?>

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.