kemper Posted August 20, 2007 Share Posted August 20, 2007 In my schedules, I have table with field of: `game_time` time NOT NULL default '00:00:00', <?php // mySQL Table $division_id = $_GET['division_id']; $sql = "SELECT * FROM `f2007_scheduling` WHERE division_id='$division_id'"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; // note change here $display_time = date("g:i a", strtotime($data['game_time'])); echo "</p> <table width='100%' cellpadding='1' cellspacing='0' border='1' bordercolor='#3c64a0'> <tr class='tbl-border'> <td><b><font size='1'>Status:</font></b></td> <td><b><font size='1'>Game ID:</font></b></td> <td><b><font size='1'>Date & Time:</font></b></td> <td><b><font size='1'>Teams:</font></b></td> <td><b><font size='1'>Field:</font></b></td> </tr>\n"; while ($row = mysql_fetch_array($result)) { echo "<tr> <td class='$tclass' valign='top'><font color='#ff0000' size='1'>".$row['status']."</font></td> <td class='$tclass' valign='top'><font size='1'>".$row['game_id']."</font></td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['game_date']=date("l, F j",strtotime($row['game_date']))."</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>at ".$row['game_time']=date("g:i a", strtotime($row['game_time']))."</font></p> </td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['home_team']." <font color='#FF0000'>(H)</font> vs.</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['visit_team']." <font color='#FF0000'>(V)</font></font></p> </td> <td class='$tclass' valign='top'><font size='1'>".$row['field']." ".$row['field_no']."</font></td> </tr>\n"; } echo "</table>\n"; // mySQL ends ?> I have some games that are blank due to field schedulers working on the specifics. Instead of by time displaying as 12:00 am, I would like to insert TBA. How do I do so? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/ Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 If the field is time, you are just going to have to do a check and use PHP for that part and change the default to TBA before you print it. Otherwise, you would have to change the field type to put that in the database. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328489 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 I cannot use an if statement or wnything else? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328491 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 Sure, you can. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328493 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 I am nor sure how to use them with data fields like this especially since there cannot really be an if_else. How can I use if? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328496 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Share Posted August 20, 2007 i would say <?php $game_time = $row['game_time'] if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } but im not having much luck with else if statements tonight lol.. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328498 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 Does it matter that my $game_time string is alterred? ".$row['game_time']=date("g:i a", strtotime($row['game_time']))." Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328501 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 I have added it to my script, but is not displaying any differently. <?php // mySQL Table $division_id = $_GET['division_id']; $sql = "SELECT * FROM `f2007_scheduling` WHERE division_id='$division_id'"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; $game_time = $row['game_time'] if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } // note change here $display_time = date("g:i a", strtotime($data['game_time'])); echo "</p> <table width='100%' cellpadding='1' cellspacing='0' border='1' bordercolor='#3c64a0'> <tr class='tbl-border'> <td><b><font size='1'>Status:</font></b></td> <td><b><font size='1'>Game ID:</font></b></td> <td><b><font size='1'>Date & Time:</font></b></td> <td><b><font size='1'>Teams:</font></b></td> <td><b><font size='1'>Field:</font></b></td> </tr>\n"; while ($row = mysql_fetch_array($result)) { echo "<tr> <td class='$tclass' valign='top'><font color='#ff0000' size='1'>".$row['status']."</font></td> <td class='$tclass' valign='top'><font size='1'>".$row['game_id']."</font></td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['game_date']=date("l, F j",strtotime($row['game_date']))."</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>at ".$row['game_time']=date("g:i a", strtotime($row['game_time']))."</font></p> </td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['home_team']." <font color='#FF0000'>(H)</font> vs.</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['visit_team']." <font color='#FF0000'>(V)</font></font></p> </td> <td class='$tclass' valign='top'><font size='1'>".$row['field']." ".$row['field_no']."</font></td> </tr>\n"; } echo "</table>\n"; // mySQL ends ?> Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328503 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 $game_time = $row['game_time'] to $game_time = $row['game_time']; Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328505 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 Yes, I did fix that line, but results are still displaying 12:00 am. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328506 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 12:00am is 00:00:00 so theirs no time set in the table maybe change <?php $game_time = $row['game_time'] if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } to $game_time = $row['game_time']; if(date("Ymd", $game_time) == 00000000) { $game_time = "TBA"; } Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328518 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 If there is no time set, the default is 00:00:00 (12:00 am) according to the table. I still get 12:00 am to desplay. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328544 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 erm.. ok try $game_time = $row['game_time']; if(date("Y", $game_time) == 1969) { $game_time = "TBA"; } hate working with dates! Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328550 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 Im still getting 12:00 am with that also. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328553 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 If it is always that same time, do a strcmp on it with 00:00:00 and see what you get. You could even try it char by char. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328557 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 what do you mean by strcmp? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328558 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Share Posted August 20, 2007 string compare -- strcmp is the function Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328561 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 I have no idea what you are asking me to do? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328563 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 The statement does not seem to do anything. <?php $game_time = $row['game_time'] if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } I changed echo $game_time ; to: echo "OK" ; Times display as they have. Times are displaying correctly as ".$row['game_time']=date("g:i a", strtotime($row['game_time']))." Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328567 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 <?php // mySQL Table $division_id = $_GET['division_id']; $game_time = $row['game_time']; $sql = "SELECT * FROM `f2007_scheduling` WHERE division_id='$division_id'"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } // note change here $display_time = date("g:i a", strtotime($row['game_time'])); echo "</p> <table width='100%' cellpadding='1' cellspacing='0' border='1' bordercolor='#3c64a0'> <tr class='tbl-border'> <td><b><font size='1'>Status:</font></b></td> <td><b><font size='1'>Game ID:</font></b></td> <td><b><font size='1'>Date & Time:</font></b></td> <td><b><font size='1'>Teams:</font></b></td> <td><b><font size='1'>Field:</font></b></td> </tr>\n"; while ($row = mysql_fetch_array($result)) { echo "<tr> <td class='$tclass' valign='top'><font color='#ff0000' size='1'>".$row['status']."</font></td> <td class='$tclass' valign='top'><font size='1'>".$row['game_id']."</font></td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['game_date']=date("l, F j",strtotime($row['game_date']))."</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>at ".$row['game_time']=date("g:i a", strtotime($row['game_time']))."</font></p> </td> <td class='$tclass' valign='top'> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['home_team']." <font color='#FF0000'>(H)</font> vs.</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$row['visit_team']." <font color='#FF0000'>(V)</font></font></p> </td> <td class='$tclass' valign='top'><font size='1'>".$row['field']." ".$row['field_no']."</font></td> </tr>\n"; } echo "</table>\n"; // mySQL ends ?> 00:00:00 time is still displaying as 12:00 am. Any ideas where I am wrong here? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-328578 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 Still having difficulties. Any suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-329086 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 i have a bad solution which i didn't want to say but if you need any solution.. <?php $game_time = $row['game_time'] var_dump($game_time); //add this line die;// add this line if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } whats returned Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-329091 Share on other sites More sharing options...
Psycho Posted August 20, 2007 Share Posted August 20, 2007 Could it be that the strtotime function interprets "TBA" as midnight? If, so then you would be overwriting TBA with midnight. Try this <?php $game_time = $row['game_time'] if ($game_time == '00:00:00') { $display_time = "TBA" ; } else { $display_time = date("g:i a", strtotime($data['game_time'])); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-329099 Share on other sites More sharing options...
kemper Posted August 20, 2007 Author Share Posted August 20, 2007 With: <?php $game_time = $row['game_time'] var_dump($game_time); //add this line die;// add this line if ($game_time == '00:00:00') { echo "TBA" ; } else { echo $game_time ; } I recieved: NULL Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-329124 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 OK cool heres the solution <?php $game_time = $row['game_time'] if ( is_null($game_time) ) { echo "TBA" ; } else { echo $game_time ; } Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/#findComment-329265 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.