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

    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Unhappy Trying To Merge Two Arrays Just Not Working


    I run a SELECT query on my mysql database. I am trying to create an array to store the results in the new array is $ar.

    I then change the SELECT statement and run it again. This time the results need to be stored in an array $ar2. These two arrays then need to be merged into 1 for further processing. Not new to programing but new to this. Any help you can give would be greatly appreciated.


    PHP Code:
    // First query run here.
      
    $result=mysql_query($sql);

    $num=mysql_num_rows($result);

    $ar=array();
    $i=0;
    while(
    $i $num)
    {
    $ar[]=mysql_result($result,$i,"pic");
    $ar[]=mysql_result($result,$i,"Title");
    $ar[]=mysql_result($result,$i,"Directions");
    $ar[]=mysql_result($result,$i,"Notes");
    }
    // Second query run here

    $result=mysql_query($sql);

    $num=mysql_num_rows($result);

    $ar2=array();
    $i=0;
    while(
    $i $num)
    {
    $ar2[]=mysql_result($result,$i,"pic");
    $ar2[]=mysql_result($result,$i,"Title");
    $ar2[]=mysql_result($result,$i,"Directions");
    $ar2[]=mysql_result($result,$i,"Notes");
    }

    //merge arrays into 1
    $ar3=array();
    $ar3=array_merge($ar,$ar2); 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    If each result is correct then this is a php question and would get better attention in the right forum!
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    thread moved
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    Originally Posted by lparnau
    I run a SELECT query on my mysql database....
    I then change the SELECT statement and run it again.
    why not run a single UNION query

    it will give you "already merged" results
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    5
    Rep Power
    0

    Sorry about the post in the wrong forum.


    Originally Posted by r937
    why not run a single UNION query

    it will give you "already merged" results
    I will do a search to find out about the single Union query sounds like it is what I need.
    Can you point me in the right direction.
    What forum was my post moved to.

    Thank You very much.

    Leonard
  10. #6
  11. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    Originally Posted by lparnau
    Can you point me in the right direction.
    google "union query tutorial"

    Originally Posted by lparnau
    What forum was my post moved to.
    gonna let you take 3 guesses

    hint: look at the title of this page

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo