CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: mysql get rows

  1. #1
    Join Date
    May 2009
    Posts
    160

    mysql get rows

    sorry not sure if i can publish a question on mysql here...

    on a query that returns n number of rows can i do it in a single statement instead of looping through...

    right now this is what i do

    Code:
    while($data = mysql_fetch_array($res) )
    {
         $temp['name'][] = $data['name'];
         $temp['state'][] = $data['state'];
         $temp['street'][] = $data['street'];
        $temp['number'][] = $data['number'];
        
    }
    cant i have mysql automatically put them all in an array for me?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: mysql get rows

    Nope. MySQL itself can only read one line of data at a time...hence why you have to recurse it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2009
    Posts
    160

    Re: mysql get rows

    Quote Originally Posted by [email protected] View Post
    sorry not sure if i can publish a question on mysql here...

    on a query that returns n number of rows can i do it in a single statement instead of looping through...

    right now this is what i do

    Code:
    while($data = mysql_fetch_array($res) )
    {
         $temp['name'][] = $data['name'];
         $temp['state'][] = $data['state'];
         $temp['street'][] = $data['street'];
        $temp['number'][] = $data['number'];
        
    }
    cant i have mysql automatically put them all in an array for me?
    Code:
    while($data[] = mysql_fetch_array($res) ) {}
    array_pop($data);
    seems to work

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: mysql get rows

    But, you're still creating the array one index at a time. You said you didn't want to do that.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured