Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2007, 12:57 AM   PM User | #1
obaluba
New Coder

 
Join Date: Aug 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
obaluba is an unknown quantity at this point
newbie simple php query!

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)


<?
$user='cdesi_admin';
$password='xxxxxx';
$database='cdesi_contacts';

$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";
$result=mysql_query($query);
$num=mysql_numrows($result);

mysql_close();

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

$i=0;
while ($i < $num){

$first=mysql_result($result,$i,"first");
$first=mysql_result($result,$i,"last");
$first=mysql_result($result,$i,"phone");
$first=mysql_result($result,$i,"mobille");
$first=mysql_result($result,$i,"fax");
$first=mysql_result($result,$i,"email");
$first=mysql_result($result,$i,"web");

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>";

$i++;
}
?>

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

thanks for looking!

obaluba is offline   Reply With Quote
Old 02-01-2007, 01:15 AM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,714
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
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.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 02-01-2007, 04:00 AM   PM User | #3
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
Yeah, what CFMaBiSmAd (what is the significance of your name BTW? ) said...
PHP Code:
$first=mysql_result($result,$i,"first");
$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 = 
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 02-01-2007, 08:23 AM   PM User | #4
obaluba
New Coder

 
Join Date: Aug 2004
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
obaluba is an unknown quantity at this point
thankyou for your direction, stupid mistake! working fine now!

thanks again
obaluba is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:54 AM.


Advertisement
Log in to turn off these ads.