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
https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/
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>

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
			 }
			 }
?>

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.