Page 1 of 1

[SOLVED] simple db retrieval

Posted: Thu Jun 24, 2004 6:08 pm
by aj2000
Hi, i cant seem to find the error in this code--this is a simple database retrival and instead of getting 3 rows(the amount of rows in the database), i get one

Code: Select all

// GENERATE A LIST OF CATEGORIES INTO AN ARRAY

$query_cat_list = "SELECT c_name FROM category";
$result_cat_list = mysql_query($query_cat_list); 

	

	//GENERATE THE ROWS

	for ($i = 0; $i < mysql_num_rows($result_cat_list); $i++) { 
  	
	$rowarray_cat_list = mysql_fetch_array($result_cat_list); 
	
	 
	echo ($rowarray_cat_list[$i]);

	}
in this code 3 rows should show up but im getting only 1...

Posted: Thu Jun 24, 2004 6:11 pm
by markl999

Code: Select all

$query_cat_list = "SELECT c_name FROM category";
$result_cat_list = mysql_query($query_cat_list) or die(mysql_error());
while($rowarray_cat_list = mysql_fetch_array($result_cat_list)){
   echo $rowarray_cat_list['c_name'].'<br />';
}

Posted: Thu Jun 24, 2004 6:11 pm
by feyd
the problem is your for loop.. specifically the echo..

using

Code: Select all

echo $rowarray_cat_list[0];
should take care of it.

simple db retrival

Posted: Thu Jun 24, 2004 6:19 pm
by aj2000
thanks alot guys..i got it to work!