Page 1 of 1
Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 2:18 pm
by motleycrewl
I'm having a hard time finding a way to exclude certain rows from being displayed in my table. Im making a simple table for hours of shops. If the shops have no entry for "friday" (friday hours) then I DONT want that row to be shown in the table, but if there is data there, then i want a new row to be shown. That might not have made too much since but below is my code:
$sql = "SELECT Name, open, close, weekday, openf, closef, friday FROM hoursfood ORDER BY Name";
$dbq = mysql_query($sql,$dbh);
echo "<TABLE align = center class=hours frame = hsides rules = rows cellpadding = 10>";
while ($row = mysql_fetch_array($dbq)) {
echo "<TR>";
echo "<TD class=padded-hours align=left>".$row{'Name'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'open'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'close'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'weekday'}."</TD>";
echo "</TR>";
// Below is the code i want to execute only if there is data in the 'friday' row
echo "<TR>";
echo "<TD class=padded-hours align=center>";"</TD>";
echo "<TD class=padded-hours align=center>".$row{'openf'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'closef'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'friday'}."</TD>";
echo "</TR>";
}
echo "</TABLE>";
mysql_close($dbh);
Any help would be very appreciated. Thanks in advance
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 2:30 pm
by kryles
Code: Select all
$sql = "SELECT Name, open, close, weekday, openf, closef, friday FROM hoursfood WHERE friday IS NOT NULL ORDER BY Name";
i think
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 2:37 pm
by motleycrewl
Thanks, but I dont think that worked.
I guess its ok if the row's where 'friday' is null is called but I just dont want them displayed in the table.
Right now they just show up as blank rows in my table. How do i get rid of those?
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 2:46 pm
by kryles
ok keep your original SELECT
Code: Select all
echo "<TABLE align = center class=hours frame = hsides rules = rows cellpadding = 10>";
while ($row = mysql_fetch_array($dbq)) {
echo "<TR>";
echo "<TD class=padded-hours align=left>".$row{'Name'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'open'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'close'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'weekday'}."</TD>";
echo "</TR>";
// Below is the code i want to execute only if there is data in the 'friday' row
if($row{'friday'} != "")
{
echo "<TR>";
echo "<TD class=padded-hours align=center>";"</TD>";
echo "<TD class=padded-hours align=center>".$row{'openf'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'closef'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'friday'}."</TD>";
echo "</TR>";
}
like that? Or do I still misunderstand :S
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 2:56 pm
by motleycrewl
Shoot, it seems like that should work.
Here is the site:
http://universitycenters.ucsd.edu/new2/index.php
If you scroll to the food-hours section you can see what im talking about: a bunch of extra <td>'s with no data to fill them because they are calling the "friday" data (which I want to leave out of the table construction)
Thanks for answering by the way!! Do you have any other ideas?
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 3:04 pm
by kryles
sorry, think it was my mistake.
do this:
Code: Select all
$sql = "SELECT Name, open, close, weekday, openf, closef, friday FROM hoursfood ORDER BY Name";
$dbq = mysql_query($sql,$dbh);
echo "<TABLE align = center class=hours frame = hsides rules = rows cellpadding = 10>";
while ($row = mysql_fetch_array($dbq)) {
if($row{'friday'} == "")
{
echo "<TR>";
echo "<TD class=padded-hours align=left>".$row{'Name'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'open'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'close'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'weekday'}."</TD>";
echo "</TR>";
}
else
{
// Below is the code i want to execute only if there is data in the 'friday' row
echo "<TR>";
echo "<TD class=padded-hours align=center>";"</TD>";
echo "<TD class=padded-hours align=center>".$row{'openf'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'closef'}."</TD>";
echo "<TD class=padded-hours align=center>".$row{'friday'}."</TD>";
echo "</TR>";
}
lets cross our fingers
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 3:13 pm
by motleycrewl
Well Ill be, it worked. You are a saint my friend. Thank you so much. until next time
Re: Thought this was easy? Exclude rows from being displayed
Posted: Tue Mar 04, 2008 3:23 pm
by kryles
really? When I look you have the same issue
