Fetching a multidimensional array - MySQL query in PHP

Discussion in 'PHP' started by timelaw, Jul 18, 2013.

  1. #1
    Hello guys!

    So I need to be able to pull this information from the database for use with AJAX, later.

    It will look like this:
    Row1, Row2, Row3
    title1, title2, title3
    track1,track2,track3
    loca1, loca2, loca3

    As you may guess, it's going to be a database storing information about songs and where they are located so they can load in jPlayer.

    mysql_query("SELECT `title`, `track`, `location` FROM `table` WHERE `album` = '$album'");
    Code (markup):
    So this is the query I will be using. Or what I think would work. So the question is, will this work to get several rows? I've tried to google and as far as I got, was that it will fetch it and then I will divide it up with a loop of some kind. I don't know how to get that loop to work though and I would really need some help with this one.

    It is supposed to go through AJAX as a last step (after it has all been sorted etc) so I can then manipulate it and generate a list with these entries for the jPlayer. So I suppose I'm supposed to run this through a json_encode(); eventually as well?

    Do you guys have any clues? :)
     
    timelaw, Jul 18, 2013 IP
  2. cochisetm

    cochisetm Member

    Messages:
    80
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #2
    This article will help you a lot: http://php.about.com/od/phpwithmysql/ss/mysql_php.htm. Once you have the data in the array ($info in the example from the link), you are correct that you would then run through json_encode().

    $my_json = json_encode($info);
    var_dump($my_json);
     
    cochisetm, Jul 18, 2013 IP