Jump to content

[SOLVED] if time is 00:00:00 display???


kemper

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.