-4
<?php
$servername = "localhost";
$serveruser = "username";
$password = "";
$connect =mysql_connect("$servername", "$serveruser", "$password");
mysql_select_db("dscbasketball") or die(mysql_error());

$result=mysql_query("SELECT * FROM players") or die(mysql_error());

$roll=mysql_fetch_array($result);

echo "Name: ".$roll['name'];

?>

this is my code,however my output is just this "Name : Melissa"

i have 7 names in the 'name' column so why am i only getting the first name?

JJaem
  • 1
  • 1
  • 2
    You need to loop through the results and stop using mysql_ functions. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Matt Apr 26 '16 at 23:55
  • oh, well in the information my teacher sent, he used those functions haha. when you say loop it.. can you explain a little more please? – JJaem Apr 27 '16 at 00:04
  • `while($roll=mysql_fetch_array($result)){...}` that's what was meant. – Funk Forty Niner Apr 27 '16 at 00:05
  • http://php.net/manual/en/control-structures.while.php *"The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration)."* - **You got it now and understand how looping works?** Or, do you want us to write it all out for you? – Funk Forty Niner Apr 27 '16 at 00:21

1 Answers1

1

Try this

<?php
$servername = "localhost";
$serveruser = "username";
$password = "";
$connect =mysql_connect("$servername", "$serveruser", "$password");
mysql_select_db("dscbasketball") or die(mysql_error());

$result=mysql_query("SELECT * FROM players") or die(mysql_error());

while($roll=mysql_fetch_array($result)) // you have to use a loop to access all entries
{
   echo "Name: ".$roll['name'];
}

?>
nikamanish
  • 662
  • 4
  • 17