savagenoob Posted January 19, 2009 Share Posted January 19, 2009 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 More sharing options...
Psycho Posted January 19, 2009 Share Posted January 19, 2009 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 https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740575 Share on other sites More sharing options...
savagenoob Posted January 19, 2009 Author Share Posted January 19, 2009 I know, but this solution would mean I would have a query for each hour on the page 8 am through 6 pm. Any other way to do it? Link to comment https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740578 Share on other sites More sharing options...
tqla Posted January 19, 2009 Share Posted January 19, 2009 no it would not because mjdamato set $time = '8:00' at the top and then included it in the mysql query. So it would only show the 8:00 hour. Link to comment https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740584 Share on other sites More sharing options...
savagenoob Posted January 19, 2009 Author Share Posted January 19, 2009 I have a table that shows all the hours 8 am through 6 pm like your outlook calendar would. The way he showed would work, but would require that I do 12 queries to see if there were any events in all the times of the day. Link to comment https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740591 Share on other sites More sharing options...
tqla Posted January 19, 2009 Share Posted January 19, 2009 Oh I see. Did you fix the syntax error in your code to see if that was this issue? Wrong: if ($row1['time'] = "08:00") Right: if ($row1['time'] == "08:00") Link to comment https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740613 Share on other sites More sharing options...
savagenoob Posted January 19, 2009 Author Share Posted January 19, 2009 Yeah, I caught that too, doesnt fix... Link to comment https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740624 Share on other sites More sharing options...
savagenoob Posted January 19, 2009 Author Share Posted January 19, 2009 Kinda solved this... doesnt do it exactly but close enough <?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 https://forums.phpfreaks.com/topic/141482-solved-echo-row-if-problem/#findComment-740636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.