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> Quote Link to comment 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> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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") Quote Link to comment 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... Quote Link to comment 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 } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.