Go Back   CP Web Hosting - reseller hosting > Server Scripting > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 11:02 AM
Senior Member
 
Join Date: Mar 2007
Posts: 193
Default create a list of the categories

In my database the table is set out like this:

id | title | category

There is about 1000 records in there and i want to be able to create a list of the categories but if i do a foreach statement i just get the same categories over and over.
Reply With Quote
  #2 (permalink)  
Old 07-04-2007, 11:04 AM
Senior Member
 
Join Date: May 2007
Posts: 329
Default

try this

Code:
$select = "SELECT subcategory FROM recipes WHERE category = '" . $row['category'] . "' GROUP BY subcategory";
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 11:06 AM
Senior Member
 
Join Date: Apr 2007
Posts: 311
Default

don't do this in php, use a mysql query.


Code:
SELECT DISTINCT ( category ) FROM mytable
OR

Code:
SELECT category FROM mytable GROUP BY category
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:52 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0