I have a table set up with a column titled has_sub which contains a tinyint value of 1 or 0 depending on whether the subcategory has another level or not. 1 = has another level and 0 = no other level.
The problem I am having is that I cannot seem to get my anchors hrefs to change depending on the has_sub field (please see the following code)
$dbc = mysql_connect($db_host,$db_user,$db_pass);
$sdb = mysql_select_db($db_database);
$category = mysql_real_escape_string($_GET['category']);
$query = "SELECT subcategory_name, has_sub FROM subcategories WHERE subcategory_parent = '$category'";
$result = mysql_query($query, $dbc)
or die (mysql_error($dbc));
while($row = mysql_fetch_array($result)) {
$subcatname = $row["subcategory_name"];
$hassub = $row["has_sub"];
if($hassub=='1')
echo "<li><a href='getsubsubs.php?category=$subcatname'>$subcatname</a></li>";
else
echo "<li><a href='listings.php?category=$subcatname'>$subcatname</a></li>";
}
As I am a beginner, chances are that I am missing something quite basic but can’t seem to figure it out. I have been looking through the documentation to no avail. Many thanks in advance.
Result of print_r($row): (from OP comment)
Array (
[0] => Alarm Systems
[subcategory_name] => Alarm Systems
[1] => 0
[has_sub] => 0
)
Array (
[0] => Building Interiors and Services
[subcategory_name] => Building Interiors and Services
[1] => 1
[has_sub] => 1
)
Everything is correct so check input on the database for errors.