View Full Version : newbie simple php query!

02-01-2007, 01:57 AM
Hi All,

Thanks for looking, I have, what I hope is a simple query, I'm a newbie to PHP and am trying to get some records to display from a mysql database done in phpmyadmin... Now the php seems to run fine, but only displays 1 row from the database which is 'Web' and it does so in the wrong place (where First name & lastname should be)


$dbh=mysql_connect ("localhost", "cdesi_admin", "xxxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("carrdesi_contacts");

$query="SELECT * FROM contacts";


echo "<b><center>Database Output</center></b><br><br>";

while ($i < $num){


echo"<b>Name: $first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";


this has had me stumped, so any advice would be very much appreciated!

thanks for looking!


02-01-2007, 02:15 AM
If you proof-read your code, you will notice that you are assigning everything to the same variable - $first.

The first step in debugging code that does not produce the expected results is to proof-read it to make sure that it contains the logic that was intended. This is true irregardless of the experience level of the programmer that wrote it.

02-01-2007, 05:00 AM
Yeah, what CFMaBiSmAd (what is the significance of your name BTW?:confused: ) said...

$first=mysql_result($result,$i,"last");//<-- should be $last =
$first=mysql_result($result,$i,"phone");//<-- should be $phone =
$first=mysql_result($result,$i,"mobille");//<-- should be $mobile =
$first=mysql_result($result,$i,"fax");//<-- should be $fax =
$first=mysql_result($result,$i,"email");//<-- should be $email =
$first=mysql_result($result,$i,"web");//<-- should be $web =

02-01-2007, 09:23 AM
thankyou for your direction, stupid mistake! working fine now!

thanks again :)