Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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