Jump to content

[SOLVED] categories-subcategories issue


stmosaic

Recommended Posts

Hi, I'm using the solution I found here under the topic "[sOLVED] category's and subcategory's" For some reason, I'm not able to get the solution to work for me.

 

What it does is only prints out the States, not the cities. No errors, just no cities despite the fact that tere are 2 state and 3 cities in the database. What I want is:

State

  City A

  City B

  City C, Etc.

 

Could a someone take a look at the code below and see if they can see why this isn't working. I appreciate the help!!

 

<?php 
$result = mysql_query("SELECT DISTINCT State FROM $DBTABLE WHERE Active='Y' ORDER BY State ASC");
while($row = mysql_fetch_array($result))
{
     //Echo out each main
 echo ("$row[state]<br>");

     $sub = mysql_query('SELECT City, CLSfolder FROM $DBTABLE WHERE (Active="Y") AND (State="' . $row['State'] . '"');
     
     while($subrow = mysql_fetch_array($sub))
     {
   //Echo out each sub.
	 echo ("<br> Cities: $subrow[City] - $subrow[CLSfolder]");
     }
}
mysql_close();		  
?>

Link to comment
https://forums.phpfreaks.com/topic/171188-solved-categories-subcategories-issue/
Share on other sites

     $sub = mysql_query('SELECT City, CLSfolder FROM $DBTABLE WHERE (Active="Y") AND (State="' . $row['State'] . '"');

 

In order for $DBTABLE to interpolate you need to have the string in double quotes.

 

     $sub = mysql_query("SELECT City, CLSfolder FROM $DBTABLE WHERE Active='Y' AND State='{$row['State']}'");

 

You don't need parentheses around each condition unless you want to specifically group them.  Which, in your case, you don't need them.  The curly braces around the associative arrays escape the single quotes.

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.