Forum Moderators: coopster
For a string, you could use strlen:
echo (strlen($row['miles'])) > 0? $row['miles'] : ' ';
Or, if the field might contain trailing blanks:
echo (strlen(rtrim($row['miles']))) > 0? $row['miles'] : ' ';
<TABLE class="tripSelect" cellspacing="1" border="1" id="table1" width="499">
<TR class="tripSelectHeader c4">
<TD width="65" align="center">
<font class="tinytextblk" face="Arial" size="1">Trip Type</font>
</TD>
<TD width="58" align="center">
<font class="tinytextblk" face="Arial" size="1">Trip Location</font>
</TD>
<TD width="131" align="center">
<font class="tinytextblk" face="Arial" size="1">State</font>
</TD>
<TD width="25" align="center">
<font class="tinytextblk" face="Arial" size="1">Date</font>
</TD>
<TD width="25" align="center">
<font class="tinytextblk" face="Arial" size="1">Miles</font>
</TD>
<TD width="52" align="center">
<font class="tinytextblk" face="Arial" size="1">view</font>
</TD>
<TD width="37" align="center">
<font class="tinytextblk" face="Arial" size="1">View</font>
</TD>
<TD width="31" align="center">
<font class="tinytextblk" face="Arial" size="1">View</font>
</TD>
<TD width="33" align="center">
<font class="tinytextblk" face="Arial" size="1">View</font>
</TD>
</TR>
<?
$host = " ";
$user = " ";
$pass = " ";
$dbname = " ";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$sql = 'SELECT * FROM trip_log ORDER BY TSpickYear, TSpickMonth, TSpickDay ASC';
$result = mysql_query($sql) or die ('<p>select died: ' . mysql_error());
while ($row = mysql_fetch_array($result)) {
$startdate = date("F d Y", mktime(0,0,0,$row['TSpickMonth'],$row['TSpickDay'],$row['TSpickYear']));
$enddate = date("F d Y", mktime(0,0,0,$row['TFpickMonth'],$row['TFpickDay'],$row['TFpickYear']));
echo '<TR class="tripSelectRow">';
echo '<TD width="65" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">',$row['triptype'],'</font>';
echo '</TD>';
echo '<TD width="58" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1"><strong><a href="/trip_log/trip_log_report.php?trip=',$row['trip_id'],'">',$row['triplocation'],'</a></strong></font>';
echo '</TD>';
echo '<TD width="131" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">',$row['state'],'</font>';
echo '</TD>';
echo '<TD width="25" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">';
echo $startdate; if ($enddate!= $startdate) echo ' to ',$enddate;
}
echo '</font>';
echo '</TD>';
echo '<TD width="25" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">';
if (!empty($row['miles'])) $row['miles'];
else echo ' ';
echo '</font>';
echo '</TD>';
echo '<TD align="Center" width="52">';
echo '<font class="tinytextblk" face="Arial" size="1">';
echo '<A HREF="javascript:void(0);" onclick="fullScreen();">Slideshow</A>';
echo '</font>';
echo '</TD>';
echo '<TD align="Center" width="37">';
echo '<font class="tinytextblk" face="Arial" size="1"> </font>';
echo '</TD>';
echo '<TD align="Center" width="31">';
echo '<font class="tinytextblk" face="Arial" size="1"> </font>';
echo '</TD>';
echo '<TD align="Center" width="33">';
echo '<font class="tinytextblk" face="Arial" size="1"> </font>';
echo '</TD>';
echo '</TR>';
?>
</TABLE>
I see three errors in your code:
1)
echo '<font class="tinytextblk" face="Arial" size="1">',$row['triptype'],'</font>';
you mean this right?
echo '<font class="tinytextblk" face="Arial" size="1">' . $row['triptype'] . '</font>';
points (.) not commas (,)
2)
> > What does the } mean?
this } is part of
while() statement and is closing output of row before than echo '</TR>'; that's not look good 3) you code say (see comments: //):
echo '<TD width="25" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">';
if (!empty($row['miles'])) $row['miles']; // <-- missed echo
else echo ' ';
echo '</font>';
echo '</TD>';
echo '<font class="tinytextblk" face="Arial" size="1">',$row['triptype'],'</font>';
you mean this right?
echo '<font class="tinytextblk" face="Arial" size="1">' . $row['triptype'] . '</font>';
points (.) not commas (,)
actually both are correct except the commas are faster. Otherwise the full string must be concatenated before it can be echo'ed
it works nicely for echo
;)
I can't seem to figure out how to get my date centered in the cell even though the cell centering is there.
echo '<TD width="25" align="center">';
echo '<font class="tinytextblk" face="Arial" size="1">';
echo $startdate; if ($enddate!= $startdate) echo ' to ',$enddate;
echo '</font>';
echo '</TD>';
something like
$startdate = str_replace [php.net](' ','<br>',$startdate);
And now a tip for outdoorxtreme1:
outdoorxtreme1 you will enjoy this:
the following is out of the present discussion, but I think than you may be interested in learn about this type of sintax <<<
# from the PHP manual:
# --------------------
print <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
# in your code would be like this:
# --------------------------------
print <<<END
<TR class="tripSelectRow">
<TD width="65" align="center">
<font class="tinytextblk" face="Arial" size="1">
1) look here: this var is between { and } --> {$row['triptype']}
2) a normal var can be writing as usual $thisVarIsOk_without_{}_signs
</font>
</TD>
...
and so on
...
END
You see the convenience?
1) you don't need "echo" at each line
2) you write less
3) you don't need escape double quotes (")
4) and is much more easy discover errors (because clean code)
if you like it, worry about:
----------------------------
<<<END <-- the word END can be any other: EOM, EOD, EOF, TEXT, CAT, DOG, etc
but must be the same at last:
END or EOM, EOD, EOF, TEXT, CAT, DOG, etc
# example:
----------
echo <<<SAMECAT
<h2>
I have a new $cat. His name is {$cat['name']}.
<br />
Now we are in the "nice cats" park.
</h2>
SAMECAT; <-- without space before SAMECAT; or you will receive an error!
NOTE:
This type of sintax is better only for output various lines.
echo is good most of times.
what do you think?
---
¦O¦
trouble is that the DESC or ASC only applies ot the column preceding it
man would it be a lot easier if you just stored a unix timestamp instead but that can be for your next project ;)
what if you get rid of the ASC or DESC all together and just leave
SELECT * FROM trip_log ORDER BY TSpickYear, TSpickMonth, TSpickDay
that should leave them in an order though it may go the wrong way.
What type are these columns? int? varchar?