I created a new table that has two columns,in the first on there are the name of the buildings and in the second the username of the user who has created them.
I want to echo all of the buildings a user has.I'm using the following code but it only echos the first "name" that matches the criteria.
<?php
/**
* @author Constantine Loukas
* @copyright 2009
*/
include ('config.php');
session_start();
$checkuser = "SELECT name FROM Users_Buildings WHERE username = '" .$_SESSION['TheNewBattles'] . "'";
$query = mysql_query($checkuser);
$userbuildings = mysql_fetch_array($query);
echo $userbuildings[0]."<br/>";
echo $userbuildings[1];
?>
I think I have to loop it somehow(although I could be completely wrong) but I can't figure it out.
Thanks in advance
I managed to make a loop but it echos the same results.
my new code is this
<?php
/**
* @author Constantine Loukas
* @copyright 2009
*/
include ('config.php');
session_start();
$checkuser = "SELECT name FROM Users_Buildings WHERE username = '" .$_SESSION['TheNewBattles'] . "'";
$query = mysql_query($checkuser);
$userbuildingrows = mysql_num_rows($query);
$counter = 1;
$userbuildings = mysql_fetch_array($query);
while ($counter <= $userbuildingrows)
{
echo $userbuildings[0]."<br/>";
$counter = $counter + 1;
}
?>