#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2014
    Posts
    10
    Rep Power
    0

    Why I getting array list instead of images


    Hello,
    I've started to learn PDO recently and now I have some troubles. Why I get array list from this instead of images?
    PHP Code:
    $get $dbh->query("SELECT SQL_CALC_FOUND_ROWS * FROM games LIMIT $start$pp") or die(print_r($dbh->errorInfo()));
    $total_rows $dbh->query("SELECT FOUND_ROWS();")->fetch(PDO::FETCH_COLUMN);

    $results $get->fetchAll(PDO::FETCH_ASSOC);
    print_r($results); 
    The result is this
    Array
    (
    [0] => Array
    (
    [id] => 1
    [nameid] => f-218
    [width] => 525
    [height] => 400
    [img] => f-218.png

    )

    [1] => Array
    (
    [id] => 2
    [nameid] => 1221
    [width] => 480
    [height] => 360
    [img] => 1221.png
    )
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    Beacuse fetrchAll returns an array containing the results. Simply put the results in a foreach loop to process it.

    Comments on this post

    • slsv agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2014
    Posts
    10
    Rep Power
    0
    I've made it like this. Is it ok? At least there are images not array list
    PHP Code:
    while ($results $get->fetch(PDO::FETCH_ASSOC)){
           
    $out .= "<dl>";
           
    $out .= "<dt><a href=\"upload/games/".$results['nameid'].".".$results['type']."\"><img src=\"".$results['img']."\" /></a></dt>";
           
    $out .= "</dl>";

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    That will work as well.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2014
    Posts
    10
    Rep Power
    0
    Apparently pdo is not so hard as i thought.. Yes, there are some differentialities but is ok for now. I thought that will be good idea first to learn mysql as basics and jump to PDO or MySQLi but I will try directly with PDO. Thank's again.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    Yep. PDO is the way to go because it does not lock you into MySQL like mysqli does, IMO.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,885
    Rep Power
    6353
    SQL is a completely separate language from PHP. You should absolutely learn SQL and PHP separately, then tie them together using something like PDO. Should you switch from MySQL to Oracle (or from PHP to Python), your base SQL knowledge will still be useful.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    378
    oh for crying out loud, if you are going to mention PDO don't support it by saying "it will allow you to switch to another db".. I know it happens rarely but then those users are experts anyways but for most of us how often do we start a project using mysql and then suddenly switch to oracle or postgres etc?

    just a little rant
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    I've had to several times. PDO was a great work saver.

    P.S. You do know what IMO means, right?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo