I have a code snippet that will return the rows of a table if the id matches the posted id, but when I place the elseif statement in to where if num_rows returns 0 or false, it doesn't post the table row properly.
I do know that if the statement returns 0 rows, it's considered as FALSE, but I cannot for the life of me figure out why it is not posting the table row as told. If I reverse the code, this functions as well through the if and elseif statement.
include '../../../db_connections/config.php';
include '../../../db_connections/opendb.php';
$query = "SELECT * FROM `items_db` WHERE `store_id` =$id AND type_id =1 AND `status_id` =1 ORDER BY `item_name` ASC";
$result = mysql_query($query,$connect) or mysql_error();
$num_rows = mysql_num_rows($result);
$row_count = mysql_num_rows($result);
$color1 = "#FFFFFF";
$color2 = "#F0F0F0";
$row_count = 0;
echo ("<table bgcolor='#FFFFFF' width='65%' border='1' cellspacing='1' cellpadding='1' align='center' style='border-collapse: collapse' bordercolor='#000000'>\n");
echo ("<tr align='center'>\n");
echo ("<td colspan='4' bgcolor='#FFCC00' align='center' valign='center'><font size='2' color='#800000' face='Tahoma'><b>Items ($num_rows)</b></td>\n");
echo ("</tr>\n");
echo ("<tr align='center'>\n");
echo ("<td width='35%' align=center valign=top><b>Name</b></td>\n");
echo ("<td width='30%' align=center valign=top><b>Manufacturer</b></td>\n");
echo ("<td width='15%' align=center valign=top><b>Type</b></td>\n");
echo ("<td width='10%' align=center valign=top><b>Price</b></td>\n");
echo ("</tr>\n");
while ($r = mysql_fetch_array($result)) {
if ( $num_rows >= 1 ) {
$row_color = ($row_count % 2) ? $color1 : $color2;
echo ("<tr align='center'>\n");
echo ("<td bgcolor='$row_color' align='left' valign='center'> <a href='ride_detail.php?id=$r[ride_id]' onclick=\"NewWindow(this.href,'name','650','550','yes');return false\">$r[item_name]</a></td>\n");
echo ("<td bgcolor='$row_color' align='left' valign='center'> <a href='manu_detail.php?id=$r[manu_id]'>$r[manufacturer_name]</a></td>\n");
echo ("<td bgcolor='$row_color' align='left' valign='center'> $r[category]</td>\n");
echo ("<td bgcolor='$row_color' align='center' valign='center'> $r[current_price]</td>\n");
echo ("</tr>\n");
$row_count++;
} elseif ( $num_rows = 0 ) {
echo ("<tr align='center'>\n");
echo ("<td bgcolor='$row_color' colspan='4' align='left' valign='center'> <i>No Current Items</i></td>\n");
echo ("</tr>\n");
}
}
include '../../../db_connections/closedb.php';
Can anyone help?