Jump to content

[SOLVED] while to display all


aebstract

Recommended Posts

Eh, sorry for so many questions today, I am having a bit of a coders block it seems :(

I am pulling information from the database and displaying it, and I want to display all of it. Each will be in its own div.. the code is only displaying the last row in the db. I know I am missing something stupid but can anyone tell me what is wrong? Thanks.

 

<html>
<head>
<link href="stylesheet.css" rel="stylesheet" type=text/css title=default />
</head>
<body>

<?php

mysql_connect("localhost","hmg","hillpass"); 
mysql_select_db("hmg"); 

$result = mysql_query("SELECT * FROM contact WHERE readc='0' ORDER BY id ASC") or DIE(mysql_error());
while($r=mysql_fetch_array($result)) 
{ 
$id=$r["id"];
$typec=$r["type"];
$readc=$r["read"];
$firstname=$r["firstname"];
$lastname=$r["lastname"];
$email=$r["email"];
$body=$r["body"];
$company=$r["company"];
$website=$r["website"];
$telephone=$r["telephone"];
$address=$r["address"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];
$ip=$r["ip"];

echo "
<div id=\"contactdiv\">
$firstname $lastname
$email
$body
</div>
";

}


?>


</body>
</html>

 

 

edit: ps - I am sure I could do it with some for statement, but can't it be done with this while statement?

Link to comment
https://forums.phpfreaks.com/topic/42718-solved-while-to-display-all/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.