Jump to content

[SOLVED] if do while else


AV1611

Recommended Posts

this script shows the table even if there are no rows returned.  How do I make the table not appear? I can't figure out how to make this if do while else or is there another way.  I can only figure out how to fire the query twice, once as an if then again as a while but that seems quite lame...

[code] echo "<center><table style='border-collapse:collapse; border-color:#999' border='1' cellpadding='5'><tr><td>GUID</td><td>NAME</td><td>LINK</td></tr>";
$result = mysql_query("SELECT `GUID`,`A`,`LISTER` from mbl_copy where `GUID` like '$q'");
while($row=mysql_fetch_array($result)){
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>";
if ($row[2]=='AASA')
{
echo "<a href='http://appeals.aaserveradmins.com/index.php?guid=".$row[0]."&Submit=Submit'>".$row[2]."</a>";
}
elseif ($row[2]=='AON')
{
echo "<a href='http://www.emailcart.net/airdale/index.php?detail=".$row[0]."&Submit=Submit'>".$row[2]."</a>";
}
elseif ($row[2]=='ACI')
{
echo "<a href='http://blmservices.com/~osprey/aao/aci.php?GUID=".$row[0]."' target='_blank'>ACI</a>";
}
elseif ($row[2]=='PsB')
{
echo "<a href='http://www.punksbusted.com/cgi-bin/membership/rpi.cgi?par=".$row[0]."' target='_blank'>PsB</a>";
}
else
{
echo $row[2];
}
echo "</td></tr>";
}
echo "</table>";[/code]
Link to comment
https://forums.phpfreaks.com/topic/32187-solved-if-do-while-else/
Share on other sites

mysql_num_rows()

something like...

[code]
<?php
$result = mysql_query("SELECT `GUID`,`A`,`LISTER` from mbl_copy where `GUID` like '$q'");
if(mysql_num_rows($result) != 0){
echo "<center><table style='border-collapse:collapse; border-color:#999' border='1' cellpadding='5'><tr><td>GUID</td><td>NAME</td><td>LINK</td></tr>";
while($row=mysql_fetch_array($result)){
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>";
if ($row[2]=='AASA')
{
echo "<a href='http://appeals.aaserveradmins.com/index.php?guid=".$row[0]."&Submit=Submit'>".$row[2]."</a>";
}
elseif ($row[2]=='AON')
{
echo "<a href='http://www.emailcart.net/airdale/index.php?detail=".$row[0]."&Submit=Submit'>".$row[2]."</a>";
}
elseif ($row[2]=='ACI')
{
echo "<a href='http://blmservices.com/~osprey/aao/aci.php?GUID=".$row[0]."' target='_blank'>ACI</a>";
}
elseif ($row[2]=='PsB')
{
echo "<a href='http://www.punksbusted.com/cgi-bin/membership/rpi.cgi?par=".$row[0]."' target='_blank'>PsB</a>";
}
else
{
echo $row[2];
}
echo "</td></tr>";
}
echo "</table>";
}
?>
[/code]

I might have typo'd something since the tabbing confused my sleep-deprived eyes, but you get the idea

Archived

This topic is now archived and is closed to further replies.

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