Skip to content
WJunction - Webmaster Forum

List category ID's

Status
Not open for further replies.

Apathetic

Experienced Member
899
2011
241
I want to list all the categories in a page. Each posts have a column with their corresponding category id (numerical). Now how do i list all the categories in a page?

PHP:
$db = mysql_connect(HOST,UNAME,PASS);
mysql_select_db(DBNAME);
$query = mysql_query("select * from POSTS");
while($row = mysql_fetch_object($query)){
	switch($row->category){
	case 1: echo 'Category A';break;
	case 2: echo 'Category B';break;
	case 3: echo 'Category C';break;
	case 4: echo 'Category D';break;
	case5: echo 'Category E';break;
	default: echo 'Uncategorized';
}

unfortunately this code displays the category everytime it exists :facepalm:
 

2 comments

Status
Not open for further replies.

About the author

A
Experienced Member · Joined
899
Messages
241
Reactions
43
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom