[SOLVED] simple db retrieval

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
aj2000
Forum Newbie
Posts: 11
Joined: Sun May 30, 2004 10:12 pm

[SOLVED] simple db retrieval

Post 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...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 />';
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
aj2000
Forum Newbie
Posts: 11
Joined: Sun May 30, 2004 10:12 pm

simple db retrival

Post by aj2000 »

thanks alot guys..i got it to work!
Post Reply