Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!


  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    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.

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    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!

  • #4
    New Coder
    Join Date
    Aug 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankyou for your direction, stupid mistake! working fine now!

    thanks again


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •