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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.