kemper Posted August 21, 2007 Author Share Posted August 21, 2007 I received error for no ; after $game_time = $row['game_time'] Changed to: <?php $game_time = $row['game_time']; if ( is_null($game_time) ) { echo "TBA" ; } else { echo $game_time ; } and, same result. All time still display as the time field designates. I am still receiving 12:00 am. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329390 Share on other sites More sharing options...
AndyB Posted August 21, 2007 Share Posted August 21, 2007 If echo $game_time generates 12:00 am, then what you have in the database field is 12:00 am, not 00:00:00. It's that simple, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329392 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 2007 it is displaying due to: ".$row['game_time']=date("g:i a", strtotime($row['game_time']))." Field from table: `game_time` time NOT NULL default '00:00:00', Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329393 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 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') { $game_time = "TBA" ; } else { $game_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 ?> I tried changing: else { $game_time = date("g:i a", strtotime($row['game_time'])); } to: elso { $game_time = "ok" ; } This changed nothing in the results. All dates are showing as they have been all along. I do not think that the if statement is correct. Any other suggestions??? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329429 Share on other sites More sharing options...
AndyB Posted August 21, 2007 Share Posted August 21, 2007 <?php $game_time = $row['game_time']; if ( is_null($game_time) ) { echo "TBA" ; } else { echo $game_time ; } and, same result. All time still display as the time field designates. I am still receiving 12:00 am. That's your code. It appears to prove conclusively that $game_time = 12:00 am. That's what your post says. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329437 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 2007 That is not my code. That was something that MadTechie asked me to do. 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 Table: CREATE TABLE `f2007_scheduling` ( `status` text NOT NULL, `division_id` int(5) NOT NULL default '0', `game_id` int(6) NOT NULL default '0', `game_date` date NOT NULL default '0000-00-00', `game_time` time NOT NULL default '00:00:00', `home_team` varchar(50) NOT NULL default '', `field` text NOT NULL, `field_no` text NOT NULL, `visit_team` varchar(50) NOT NULL default '', PRIMARY KEY (`game_id`), Here is a line from my table that I keep viewing: INSERT INTO `f2007_scheduling` VALUES ('Time ?', '14 A2 Red', 204205, '2007-09-15', '00:00:00', 'Team A', 'Home Field', '1', 'Team B'); According to the code, it should display 12:00 am, but I want it to say "TBA". These kids are not going to play at 12:00 am. 00:00:00 is the default setting if no time is set. Whats the deal? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329441 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 2007 Anyone? Bueller?! Bueller?! Bueller?! Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329898 Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 does this display null ? $game_time = $row['game_time']; var_dump($game_time); //add this line Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-329904 Share on other sites More sharing options...
phpknight Posted August 21, 2007 Share Posted August 21, 2007 I don't necessarily want you to give up, but I have issues with mySQL time fields all the time. I still don't know what php function gets the time in the right format for the time field. You *could* just put hour minute and second INT values in your database. That would get rid of this specific problem. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330345 Share on other sites More sharing options...
akitchin Posted August 21, 2007 Share Posted August 21, 2007 or instead, you could use MySQL to its full potential here. you can use IF() to pull out the correct value: SELECT IF(game_time <> '00:00:00', game_time, 'TBA') AS new_game_time FROM table if your game_time column actually defaults to NULL (as madtechie is implying might be the case), you can use IFNULL(). have a look in the MySQL manual in the section Functions and Operators for more info. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330347 Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2007 Share Posted August 21, 2007 "00:00:00 is the default setting if no time is set. Whats the deal?" The field is set to NOT NULL, so it must put something in there. If you rather have nothing than 00:00:00, allow the field to be NULL. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330348 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 2007 MadTechie: It did return "NULL". BlueSkyIS: I alterred to allow NULL. Now my results still return 12:00 am instead of nothing, even after removing <?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/page/2/#findComment-330355 Share on other sites More sharing options...
akitchin Posted August 21, 2007 Share Posted August 21, 2007 did it return a NULL variable type, or a string variable type with the value 'NULL'? there's a big difference. if they are going in as NULL (rather than 0000-00-00), try this: SELECT IFNULL(game_time, 'TBA') AS game_time FROM table this will select game_time if it isn't NULL, but if it is NULL, will pull 'TBA' instead. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330356 Share on other sites More sharing options...
kemper Posted August 21, 2007 Author Share Posted August 21, 2007 how do I add that into my code? Does this replace or remove the If Statement? I do not think I replace my $sql = "SELECT ... with this SELECT Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330359 Share on other sites More sharing options...
akitchin Posted August 21, 2007 Share Posted August 21, 2007 simply add it into your current select query - it's considered a field like any other: $sql = "SELECT *, IFNULL(game_time, 'TBA') AS new_game_time FROM `f2007_scheduling` WHERE division_id='$division_id'"; Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330367 Share on other sites More sharing options...
kemper Posted August 22, 2007 Author Share Posted August 22, 2007 I must be doing something wrong. Null appears as 12:00 am also. <?php // mySQL Table $division_id = $_GET['division_id']; $sql = "SELECT *, IFNULL(game_time, 'TBA') AS new_game_time FROM `f2007_scheduling` WHERE division_id='$division_id'"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; 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 ?> Table is configured as: CREATE TABLE `f2007_scheduling` ( `status` text NOT NULL, `division_id` int(5) NOT NULL default '0', `game_id` int(6) NOT NULL default '0', `game_date` date NOT NULL default '0000-00-00', `game_time` time default '00:00:00', `home_team` varchar(50) NOT NULL default '', `field` text NOT NULL, `field_no` text NOT NULL, `visit_team` varchar(50) NOT NULL default '', Is this correct? Or, where am I wrong? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330530 Share on other sites More sharing options...
Psycho Posted August 22, 2007 Share Posted August 22, 2007 Did you ever try the code samples you were given - EXACTLY as they were posted? Or did you try and work those into your script above? I ask because several of those samples were posted to see what exactly what was being returned. What you have above will not work. And from the previous posts you keep changing things so this is becommng a moving target. Once you changed the db to allow nulls, did you go back and set the values to null for all the records that previously had 00:00:00? If not, that query above will continue to return a time instead of "TBA". And, even if you did set the time to null for all the appropriate records, it will still fail to give you the results you want. Because if the time for a record is returned as "TBA" you will then change that value once you pass that value to the date() function. Try this code - exactly as it is posted and see what results you get (comment one of the two lines out as appropriate based upon whether you have nulls or 00:00:00 in your existing records) <?php $division_id = $_GET['division_id']; $sql = "SELECT * FROM `f2007_scheduling` WHERE division_id='$division_id'"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { //Comment out one of these lines based upon what you are storing for "no time" //$game_time = ($row['game_time']!=null)?date("g:i a", strtotime($row['game_time'])):'TBA'; $game_time = ($row['game_time']!='00:00:00')?date("g:i a", strtotime($row['game_time'])):'TBA'; echo $row['game_id'] . ' : ' . $row['game_time'] . '<br>'; } ?> Also, I am perplexed why you are doing a variable assignment within your echo. You are not using that variable anywhere, so it is a waste. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330656 Share on other sites More sharing options...
kemper Posted August 22, 2007 Author Share Posted August 22, 2007 That shows how much of a noob I am. Sorry. That code results in time as they are in the table (eq. 14:30:00), with blank info for NULL game_times. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330892 Share on other sites More sharing options...
kemper Posted August 22, 2007 Author Share Posted August 22, 2007 FYI: I would be satisfied with the NULL game_time returning a blank result rather than TBA. It seems like, when =date("g:i a", strtotime($row['game_time'])) is added to my echo is where thinks go astray. That alteration is what brings back the 12:00 am. Why is that? And/or is there a way to fix my issue? Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330894 Share on other sites More sharing options...
Psycho Posted August 22, 2007 Share Posted August 22, 2007 Ok, that was the exact issue I identified on page one of this post. The code was setting the time value to TBA, but then when you ran the date() function on it, the function got "confused" because you passes it something it coudn't interpret as a time. That is why all of the help that others were trying to provide earlier was not working. The provided code snippets needed to be implemented exactly as they were provided as they were trying to debug the problem. I have two last comments. First, did you try uncommenting out the first $game_time = line and commenting out the second as I suggested if you actually had nulls in your table??? Second why are you using this in your echo statement: $row['game_time']=date("g:i a", strtotime($row['game_time'])) That makes no sense why you would assign a value to the variable in the echo statement instead of just displaying the time. Anyway, based upon what I *think* is going on here, try this: <?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()); 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)) { $game_time = ($row['game_time']!=null)?date("g:i a", strtotime($row['game_time'])):'TBA'; 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'>".date("l, F j",strtotime($row['game_date']))."</font></p> <p style='margin-top: 0; margin-bottom: 0'><font size='1'>at ".$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"; ?> Also, you should not use FONT tags - they have been deprecated for a long time. You are already using class tags. Add the font properties to those classes. Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330909 Share on other sites More sharing options...
kemper Posted August 22, 2007 Author Share Posted August 22, 2007 Freakin' A! I have a lot to learn. You suggestion did do the trick. 1. - I did not try uncommenting out the first $game_time. I missed this, yet not totally understanding its relationship. 2. - I tried so many things in the echo. You had suggested something like that on: August 20, 2007, 01:44:35 PM I have been playing with this for so long. If all times were provided in a timely manner as I requested, we prolly would not have to go through this, but I will keep learning. Thanks Man! Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330913 Share on other sites More sharing options...
Psycho Posted August 22, 2007 Share Posted August 22, 2007 1. - I did not try uncommenting out the first $game_time. I missed this, yet not totally understanding its relationship. I was using a ternary operator which is basically a shorthad way of doing an if/else statement and which many new programmers aren't familiar with, but is a great time-saver. Here is the format: $variable = (condition) ? true_value : false_value; Here are the two lines I had, with an explanation, for your learning pleasure: $game_time = ($row['game_time']!=null)?date("g:i a", strtotime($row['game_time'])):'TBA'; This line would be used where the records without a valid time have a null value. If the returned value for that record does not equal null, then $game_time = date("g:i a", strtotime($row['game_time'])), otherwise it will equal 'TBA' $game_time = ($row['game_time']!='00:00:00')?date("g:i a", strtotime($row['game_time'])):'TBA'; This line would be used where the records without a valid time have 00:00:00 as their value. If the returned value for that record does not equal '00:00:00', then $game_time = date("g:i a", strtotime($row['game_time'])), otherwise it will equal 'TBA' Quote Link to comment https://forums.phpfreaks.com/topic/65756-solved-if-time-is-000000-display/page/2/#findComment-330939 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.