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 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2005
    Location
    Louisville, Kentucky
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting information from a mySQL database.

    Thanks to all the people who helped me connect to a mySQL database, but now, im having problems with actually getting information from the database, I've tried diffrent functions, but I'm still unsuccessful. Is there a function used for getting information from a table in a mySQL database, and also, I'm using phpAdmin, so I'm wondering if I'm actually adding information correctly to the field in that specific table.

    Thank you for reading.
    What was I thinking?
    Email Me

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First you run the query, then use mysql_fetch_array() (or mysql_fetch_assoc() which is just mysql_fetch_array($result, MYSQL_ASSOC)):

    PHP Code:
    $link mysql_connect('localhost''user''pass');
    mysql_select_db('db');
    $query mysql_query('SELECT * FROM users');

    // To fetch a single row we'd just get rid of the while loop...
    while ($row mysql_fetch_array($query) {
         echo 
    'User: ' $row['username'] . '<br />'// This would be the usename column

    This simple little snippit would connect to a database, select the db, run a query to select all columns in the users table, and then loop through each row, outputting the username.
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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