[SOLVED] Getting info out of my arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zoe
Forum Commoner
Posts: 36
Joined: Sat Jun 11, 2005 11:51 am
Location: Glasgow

[SOLVED] Getting info out of my arrays

Post by zoe »

This must be so simple to somebody that knows what they're doing, but I don't know what to search for to get an answer!
I'm quite happy normally pulling arrays out of a DB, but now I'm trying to extract a list of distinct results from a single field and am not sure how to go about it. I've got this so far:

Code: Select all

$query = "SELECT DISTINCT Category FROM alba_catalogue ORDER BY Category asc";
	$result = mysql_query($query);
	
	while($category = mysql_fetch_array($result)){
		echo"<p>$category</p>"; //Here's where I want a list of each of the categories
		}
It's not all bad as at least it seems to be returning the right number of results, but rather than the category name, I'm just getting 'array' as I don't know what to do to $category to get the info out. Any advice would be very much appreciated. Thanks.
Last edited by zoe on Tue Feb 27, 2007 6:34 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$query = "SELECT DISTINCT Category FROM alba_catalogue ORDER BY Category asc";
$result = mysql_query($query) or die(mysql_error());

while( false!==($row=mysql_fetch_array($result)) ) {
	echo '<p>', htmlentities($row['Category']), "</p>\n";
}
zoe
Forum Commoner
Posts: 36
Joined: Sat Jun 11, 2005 11:51 am
Location: Glasgow

Post by zoe »

Thank you so much. Works a treat.
Post Reply