SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Trouble pulling data from MySQL

    First off, please excuse my ignorance, it has been a while since I have written any code. Trying to run a pretty simple query here to pull data from a MySQL database. The code is as follows;

    PHP Code:
    $sql 'SELECT type, value FROM ' $TBLPREFIX 'config';
    $data mysql_query($sql);
    $rs mysql_fetch_array($data);

    print_r($rs); 
    The print_r only shows the first row being fetched. There are currently three rows in the table. Not sure what I am missing here.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,408
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi zkiller,

    mysql_fetch_array only fetches a single row of results at a time. You can loop over the results with a while loop:
    PHP Code:
    while($row mysql_fetch_array($data)) {
        
    print_r($rs);

    You shouldn't really use the mysql functions any more though, as they've been depreciated and will be removed from PHP at some point. It's better to use mysqli or PDO.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I knew I was missing something. Oh and thanks for the info the mysql function being deprecated soon. After some quick research, I think I will rewrite using PDO. I quite like it.


Bookmarks

Posting Permissions

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