stmosaic Posted August 20, 2009 Share Posted August 20, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/171188-solved-categories-subcategories-issue/ Share on other sites More sharing options...
Maq Posted August 20, 2009 Share Posted August 20, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/171188-solved-categories-subcategories-issue/#findComment-902747 Share on other sites More sharing options...
stmosaic Posted August 20, 2009 Author Share Posted August 20, 2009 Maq, Thank you, that works perfectly! Yeah, I did overlook the $DBTABLE needing double quotes. The associative array syntax with the curly braces is one I'm not as practiced with - thanks for the explanation. Quote Link to comment https://forums.phpfreaks.com/topic/171188-solved-categories-subcategories-issue/#findComment-902752 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.