0

I want to retrieve firstName from the member table in z1760359 . When I execute the code , its only displaying the first name in the member table and the rest is not displayed

Member table in z1760359

select firstName from member

| Roberto   |
| Savannah  |
| Sai       |
| Adarsh    |
| Jane      |

$hostname='localhost';
$username='root';
$pass='';  
$db="z1760359";
$db1=mysqli_connect($hostname,$username,$pass,$db) or die('Oops something     went wrong ');
$query= "SELECT firstName from member";
$message1=mysqli_query($db1,$query);
$message2=mysqli_fetch_assoc($message1);
foreach($message2 as $r1)
  {
     echo"$r1";

     echo"<br>";
   }
?>
1
  • 1
    when we use mysqli_fetch... & looping after it, the first result can't be shown. Use myqli_fetch.. in while loop to display the records... Commented Apr 20, 2015 at 6:33

1 Answer 1

3

The code is storing only the last row to the variable. Try with -

while($message2=mysqli_fetch_assoc($message1)) {
    echo $message2['firstName'];
    echo"<br>";
}

Use 'while' loop Instead of using foreach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.