View Full Version : populating the category and subcategory

08-24-2011, 01:37 AM
In my sql db I've got a table with a category and a subcategory.
Now I want to extract all values and place them in a javascript file.

The javascript file looks like this:

parent_array['Audi'] = ['A3','A4','A5','A6','A8','Q5','Q7','S3','S4','S5','S6','S8','RS6'];
parent_array['Dacia'] = ['Sandero','Logan'];
parent_array['FIAT'] = ['Bravo','Punto','Grande Punto'];

As you can see there are categories and subcategories in the javascript part.
How can I retrieve my db categories and subcategories to place them in the javascript.

I don't know which sql statement I should use, I got this part but don't know how to continue.

$q = mysql_query("select * from mydb");

if(!$q) {echo "A DB error occured, please try again later. Error: ". mysql_error();}else{
while($nv=mysql_fetch_array($q)) {$valueFromDb = $nv['Category']; $valueFromDb2=$nv['Subcategory'];

/* Do some stuff here */



08-24-2011, 04:37 PM
What are your tables designed like?