Question:
Building a dynamic menu in PHP from a MySQL database?
anonymous
2008-01-17 15:30:56 UTC
I have 4 tables in a relational mysql database in the context of a catalogue. 1 table defines the main categories, i.e. Food & Drink with a number as the p.key to relate this to other tables. 1 Table (the main bulk of data) contains a list of shops with numbers next to each with a number to represent which category theyre in. Another table defines subcategories, i.e. Bars & Restaurants, Take Aways..with a field to relate these subcategories to its main category. The final table has information (numbers) in it to say which Shop is in which subcat. 1 shop can be in many categories. Now the question:

I want a dynamic menu for a webpage in PHP that does this:

1. Echo the friendly name of the first main category.
2. Echo all subcategories in this main category and at the side of each do a count to show how many shops are in each subcategory.
3. Echo all other main categories with their subcategories and counts.

Suspect i need2use foreach and while/for loop or a function. Thnx,Daz
Three answers:
anonymous
2008-01-17 15:52:25 UTC
If you use a query with the where set to the link id you can then use the following in a link_ID for each loop:

$shop_count = 0;

$result1 = mysql_query("select * from food_table where link_ID = 'for_loop_count'");

while ($record1 = mysql_fetch_array($result1)){

$shop_count ++;

}

$display .=" --- "

// this string can be built to include the html for each stage

// finish the loop;

}

echo $display;
anonymous
2016-04-06 03:19:57 UTC
Justin - I've used Wordpress in the past and that's been pretty good. Could change the css - the main pages they have a link in the admin pages and for extra pages easily done. Don't know the deets about why Joomla isn't loading the css for the other pages, but look at where you're putting the page at. At the CMS systems need you to have files in absolutely specific directories - that might be the prob. Good luck!
Rasmah.com
2008-01-17 15:37:03 UTC
You just need java script and php that is all ..



the java script that to create list ..



and php to fild this list


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...