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 7 of 7
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Question show existing data from mysql problem!

    Hello,

    I'm trying to use this code:

    PHP Code:
    <?php
    $link 
    mysql_connect('localhost''traumati_six''******');
    mysql_select_db ("traumati_six");

    $result mysql_query('SELECT name FROM accounts');
    if (!
    $result) {
       die(
    'Could not query:' mysql_error());
    }
    echo 
    mysql_result($email); // outputs email address

    mysql_close($link);
    ?>

    but i keep getting this error:
    Could not query:No database selected


    can anyone tell me what i've done wrong here??

    thanks in advance for your site!
    -SiX

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, the most likely cause judging from that error message is that either the login details are incorrect or the database isn't called traumati_six. Try specifically outputting a failure from mysql_connect and mysql_select_db to find out where it's failing:
    PHP Code:
    $link mysql_connect('localhost''traumati_six''******') or die('Login details incorrect');
    $db_selected mysql_select_db('traumati_six'$link) or die('Database name incorrect'); 

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, your right, i fixed the db name, now it connects,

    PHP Code:

    <?php
    $link 
    mysql_connect('localhost''traumati_six''six') or die('Login details incorrect');
    $db_selected mysql_select_db('test'$link) or die('Database name incorrect');

    $result mysql_query('SELECT * FROM accounts');
    if (!
    $result) {
       die(
    'Could not query:' mysql_error());
    }
    echo 
    mysql_result($email); // outputs email address

    mysql_close($link);
    ?>
    but now i'm getting this error:



    Warning: Wrong parameter count for mysql_result() in /home/traumati/public_html/six/conntemp.php on line 9

    line 9 is:
    echo mysql_result($email); // outputs email address

    now i know the name and case is correct, "email"

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ok, i found what i was doing wrong,

    PHP Code:

    <?php
    $link 
    mysql_connect('localhost''traumati_six''six') or die('Login details incorrect');
    $db_selected mysql_select_db('test'$link) or die('Database name incorrect');

    $result mysql_query('SELECT * FROM accounts');
    #if (!$result) {
    #   die('Could not query:' . mysql_error());
    #}
    echo mysql_result($result0); // outputs email address
    print "<br />";
    echo 
    mysql_result($result1); // outputs email address

    mysql_close($link);
    ?>
    but this only calls the first row,
    so i have two questions,

    1. how to i call other rows? like username,

    2. how do i loop through the data to show all the data in the table??


    thanks again for your time!
    -SiX

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    while($row = mysql_fetch_assoc($result))
    {
    //echo whatever you want here
    }

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    if I use that code, it goes into a never ending loop, and just shows the same data over and over again

    and how to i show other data from other columns? for some reason it only shows data from the first one?

    -SiX

  • #7
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's something else wrong if mysql_fetch_assoc() is overlooping. Once your mysql_fetch_assoc() will return FALSE once it's gone through the whole result set, breaking your while loop. Without seeing the code, though, it's hard to say what's causing it.


  •  

    Posting Permissions

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