SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Store MySQL results set in PHP variable

    Hi,

    What's the best way to store a MySQL result set (with multiple rows in the set) in a PHP variable?
    Last edited by Tipem; Jul 23, 2009 at 07:05.
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    What is a PHP storable variable?

  3. #3
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. Weird wording:

    How do I store a MYSQL result set (with multiple rows in that set) in a PHP variable?
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  4. #4
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    According to your explanation...
    PHP Code:
    // Now mysql result set is stored in php variable.
    $result mysql_query("SELECT * FROM foo"); 
    Or if you meant that you want the rows as an array. Then you need to loop through the result set.
    PHP Code:
    $array = array();
    while(
    $row mysql_fetch_object($result))
    {
        
    $array[] = $row;

    Or you mean something else...? I am confused..

  5. #5
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    $result = mysql_query($querystring, $dbconn)

  6. #6
    Pandora Tipem's Avatar
    Join Date
    Feb 2006
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, TeNDoLLA. Your second example is perfect. Just serialize() that $array to store it in a PHP variable.

    Solved! Thanks again all! You guys rock!
    Tipem no fancy sig, yup
    Need Neopets Help? Try Neopets
    fun adoptable eggs

  7. #7
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you perhaps mean string when you say variable?
    Otherwise $result, $row, $array are all 'variables' anyway.


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
  •