Hello,

I'm trying to echo $pet_list, but it only gives me one value of the array.

part of core.php (which is included in create_pet.php)

$pet_list = mysql_fetch_assoc(mysql_query("SELECT * FROM ".$db_prefix."uberpets_pet_species"));

part of create_pet.php

if ($step == "1"){
	opentable("Create a Pet");
	echo "<center>Here you can create your first pet! Please choose. ".$pet_list['name']." You will be able to change the color.</center><br /><br />";
		
	$count = count($pet_list, COUNT_RECURSIVE);
	$display_columns = 4; //amount of columns
	$padding = ($display_columns-1)-(($count-1)%$display_columns);
	echo '<table width="100%">';
		// Let's begin our loop.
		for($qweqwe=0; $qweqwe<$count; $qweqwe++){
			if($qweqwe%$display_columns == 0)
				echo '<tr>';
			echo '<td width="25%">';
			echo '<center><a href="'.FUSION_SELF.'?step=2&species='.$pet_list['name'].'">';
			echo '<img src="'.PETS.''.$pet_list['name'].'/Normal.gif" /></a><br />';
			echo '<b>'.$pet_list['name'].'</b>&nbsp;';
			echo '</center><br /><br /><br />';
			echo '</td>';
									
									
			 if($qweqwe%$display_columns == $display_columns-1)
				echo '</tr>';
									
		}
	if($padding!=0){
		for($qweqwe=0;$qweqwe<$padding;$qweqwe++)
			echo '<td></td>';
		echo '</tr>';
	}
	echo '</table>';
	closetable();
}

Here's the mysql table:

CREATE TABLE `fusion_uberpets_pet_species` (
  `sid` int(100) NOT NULL auto_increment,
  `name` text NOT NULL,
  `info` text NOT NULL,
  `folder` text NOT NULL,
  PRIMARY KEY  (`sid`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

-- 
-- Dumping data for table `fusion_uberpets_pet_species`
-- 

INSERT INTO `fusion_uberpets_pet_species` (`sid`, `name`, `info`, `folder`) VALUES (1, 'Grr', 'Grrs are kewl', 'Grr');

$pet_list = mysql_fetch_assoc(mysql_query("SELECT * FROM ".$db_prefix."uberpets_pet_species"));

This will definitely return 1 record.

$result = mysql_query("SELECT * FROM ".$db_prefix."uberpets_pet_species");
while($row = mysql_fetch_assoc($result)) {
$pet_list[] = $row;
}

Notice the use of while :)

Ok, I guess my question was worded wrong. What happens when I use this code is that the table created displays 4 pets called "Grr".

So, the problem is solved now ?

Not exactly.
I've tried solving it again, and it still doesn't work...

It's at http://www.clububer.com/infusions/uberpets/create_pet.php?step=1 .

Here's my new code:

$query = dbquery("SELECT name FROM ".$db_prefix."uberpets_pet_species");
$pet_species = dbarray($query);					
	echo "<center>Here you can create your first pet! Please choose. $i You will be able to change the color.</center><br /><br />";		
							
			$count = dbrows($query);
			$display_columns = 4;
			$padding = ($display_columns-1)-(($count-1)%$display_columns);
			echo '<table width="100%">';
			// Let's begin our loop.
				for($i=0; $i<$count; $i++)
				{
				    if($i%$display_columns == 0)
						echo '<tr>';
									
					$petspecies = dbarray(dbquery("SELECT * FROM ".$db_prefix."uberpets_pet_species WHERE sid='".$i."'"));
				    echo '<td width="25%">';
				    echo '<center><a href="'.FUSION_SELF.'?step=2&species='.$petspecies['name'].'">';
					echo '<img src="'.PETS.''.$petspecies['name'].'/Normal.gif" /></a><br />';
					echo '<b>'.$petspecies['name'].'</b>&nbsp;';
					echo '</center><br /><br /><br />';
				    echo '</td>';
									
									
					   if($i%$display_columns == $display_columns-1)
							echo '</tr>';
									
								}
			if($padding!=0){
				for($i=0;$i<$padding;$i++)
			        echo '<td></td>';
			    echo '</tr>';
			}
			echo '</table>';

dbarray is the same as mysql_fetch_assoc.
dbquery is the same as mysql_query.
dbrows = mysql_num_rows
FUSION_SELF is the same as PHP_SELF.

Sorry, solved it myself. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.