Search the Community
Showing results for tags 'if else statement'.
-
I am working on a project that involves providing details for county government, and if applicable, cities independent of county oversight. Virginia is a state with a lot of independent cities, so I wanted to echo them in a separate list underneath the county governments. This code works fine when displaying Virginia information. However, I would like to hide the Independent Cities heading in every other state. For some reason, this code still echoes the Independent Cities heading in states without independant cities in the database. Any thoughts or wisdom? (sorry for pasting the whole bulky code) $query = "SELECT * FROM state WHERE st_id=$statecode"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); $row = mysql_fetch_assoc($result); $state_name=$row["st_name"]; $state_note=$row["state_notes"]; echo "<h2>Counties of " . $state_name; "</h2>\n"; $query = "SELECT * FROM counties WHERE st_id=$statecode AND visible=1 ORDER BY county_name ASC"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); echo "<table width=100%><tr><td valign=top width=33%>\n"; $count = 1; $col = 0; $rowcount = (int)(mysql_num_rows($result) / 3) + 1; $remainder = mysql_num_rows($result) - ($rowcount - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["county_id"]."\">".$row["county_name"] . "</style></a><br />\n"; $count = $count + 1; if ((($remainder > 0) && ($count == ($rowcount + 1))) || (($remainder <= 0) && ($count == $rowcount))) { $col = $col + 1; if ($col!=3) { echo "</td><td valign=top width=33%>\n"; $count = 1; if ($remainder > 0) $remainder = $remainder - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result); /* ********************************************************* */ $query2 = "SELECT * FROM cities WHERE st_id=$statecode AND visible=1 ORDER BY city_name ASC"; $result2= mysql_query($query2) or die("Query $query failed : " . mysql_error()); $city_id = $row['city_id']; $city_name = $row['city_name']; if ($city_id!="") { echo "<h3>Independent cities of " . $state_name; "</h3>\n"; echo "<table width=100%><tr><td valign=top width=33%>\n"; $count2 = 1; $col2 = 0; $rowcount2 = (int)(mysql_num_rows($result2) / 3) + 1; $remainder2 = mysql_num_rows($result2) - ($rowcount2 - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["city_id"]."\">".$row["city_name"] . "</style></a><br />\n"; $count2 = $count2 + 1; if ((($remainder2 > 0) && ($count2 == ($rowcount2 + 1))) || (($remainder2 <= 0) && ($count2 == $rowcount2))) { $col2 = $col2 + 1; if ($col2!=3) { echo "</td><td valign=top width=33%>\n"; $count2 = 1; if ($remainder2 > 0) $remainder2 = $remainder2 - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result2); /* ********************************************************* */ } ?>