snickers123 Posted August 18, 2013 Share Posted August 18, 2013 I run a SELECT query on my mysql database. The results are to be stored in an array $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 mearged into 1 for further processing. Not new to programing but new to this. Any help you can give would be greatly appreciated. <?PHP // 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); //array_merge($array1, $array2); ?> Link to comment Share on other sites More sharing options...
HartleySan Posted August 18, 2013 Share Posted August 18, 2013 What is the problem with the merge? In other words, why isn't it merging the way you want? What are you expecting, and what are you actually getting? Also, I would recommend using the MySQLi family of functions instead of the MySQL functions. Link to comment Share on other sites More sharing options...
Antonio Conte Posted August 18, 2013 Share Posted August 18, 2013 If you are just going to merge them without doing anything else, why not build a single array instead? Link to comment Share on other sites More sharing options...
snickers123 Posted August 19, 2013 Author Share Posted August 19, 2013 I decided to go with the SELECT with a UNION ALL. I have used the first statements many time and it works when, but when I ad the "UNION ALL" or just the "UNION" statement it stops working. There is no error messages the script runs to the last else "No Records" All the variables are preset and working. I have tested everything up to the SELECT statements. $result=mysql_query($sql);print_r($result); prints out "Rescorce#3" The script runs all the way through to the ending else "No Records". The problem is when it gets to the SELECT its like the SELECT statements never ran? $sql="SELECT * FROM recipes WHERE Cat='$cat'and Eggs='$Eggs' and Fruitose='$Fruitose' and Gluten='$Gluten' and Lactose='$Lactose' and Nuts='$Nuts' and Soy='$Soy' and LowFat='$LowFat' and Diabetice='$Diabetice' and Vegan='$Vegan' UNION ALL SELECT * FROM recipes WHERE Cat='$cat'and Eggs='$Eggs2' and Fruitose='$Fruitose2' and Gluten='$Gluten2' and Lactose='$Lactose2' and Nuts='$Nuts2' and Soy='$Soy2' and LowFat='$LowFat2' and Diabetice='$Diabetice2' and Vegan='$Vegan2'"; Link to comment Share on other sites More sharing options...
HartleySan Posted August 19, 2013 Share Posted August 19, 2013 What do the first and second queries return by themselves? Link to comment Share on other sites More sharing options...
Recommended Posts