hello, I am trying to create a form that will query mysql to result in defining a location(three in all: country, state, city). This is all based upon drop down bars and so far I have the country select already working. It is controlled through javascript and I am not to sure if this is my problem why as I contunue, nothing is working. (do not know any javascript).
This question is directed towards the query that is for the state drop down. $countryfix = $countryList[$selected country];. print_r($countryfix) works great!It keeps up with every country as selected, although when I run this, this will not work. I have tried print_r($cityList) it returns as ( [0] => ) . might someone send me in the right direction, it would be greatly appreciated.
$querystate = ("SELECT state FROM location_root WHERE country = '$countryfix'") or die("something messed up");
$resultstate = mysql_query($querystate);
while ($rowstate = mysql_fetch_array($resultstate))
{
$categoriesstate[] = $rowstate['state'];
}
$stateArray = array_unique($categoriesstate);
$cityList = ($stateArray) ;
return $cityList;
}
help with a mysql query
Moderator: General Moderators
Re: help with a mysql query
I'm not sure what your problem is, so I'll just talk about your code. Btw, put everything in [ php ] tags.
also...
I don't quite understand why you're copying all the variables around.
In any case, the code above will work fine. If it doesn't, it's a problem somewhere else.
Try running something like this to track where something doesn't add up. If this data comes out correctly, it's a problem with the javascript. If it doesn't, it's a problem with the preceding code or the database.
Code: Select all
//mysql_error() will give you what's really wrong
//Simpler to use one line
$resultstate = mysql_query("SELECT state FROM location_root WHERE country = '$countryfix';") or die(mysql_error());
while ($rowstate = mysql_fetch_array($resultstate)) {
$categoriesstate[] = $rowstate['state'];
}
//Unless you're not posting part of the code, there's no need for all the extra variables here...
return array_unique($categoriesstate);
}Code: Select all
$cityList = ($stateArray) ; //what's with the () ????
//should be:
$cityList = $stateArray;In any case, the code above will work fine. If it doesn't, it's a problem somewhere else.
Try running something like this to track where something doesn't add up. If this data comes out correctly, it's a problem with the javascript. If it doesn't, it's a problem with the preceding code or the database.
Code: Select all
echo $countryfix;
$resultstate = mysql_query("SELECT state FROM location_root WHERE country = '$countryfix';") or die(mysql_error());
while ($rowstate = mysql_fetch_array($resultstate)) {
print_r($rowstate);
$categoriesstate[] = $rowstate['state'];
}
print_r($categoriesstate);
$categoriesstate = array_unique($categoriesstate);
print_r($categoriesstate);
return $categoriesstate;
}Re: help with a mysql query
hey, Thank you. I have tried what you have given me and it works the same way before. This leaves me to believe that it is a javascipt issue. I will find a place to trouble shoot this. thank you!