Page 1 of 1

[SOLVED] Getting info out of my arrays

Posted: Tue Feb 27, 2007 6:14 am
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.

Posted: Tue Feb 27, 2007 6:19 am
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";
}

Posted: Tue Feb 27, 2007 6:33 am
by zoe
Thank you so much. Works a treat.