chrisfane Posted July 27, 2007 Share Posted July 27, 2007 im currently executing sql queries on two seperate mysql servers. i take back each of these results into individual tables to display them. What i wanted to do was perform a merge of the two arrays, so that i could order the results by my "TimeStamp" field. When i try to perform a basic " $mergedresult = array_merge($result, $isaresult); " i get the following. " Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\Program Files\xampplite\htdocs\seatpub.php on line 164 Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\Program Files\xampplite\htdocs\seatpub.php on line 164 " Im rather new to this and so havent delt with arrays before, but im under the impression my results from the sql queries, are Assoc arrays. can these be merged ? do i need to use an alternate php function ? Thanks for any help Chris Link to comment https://forums.phpfreaks.com/topic/62003-merging-2-mysql-resultant-arrays/ Share on other sites More sharing options...
ToonMariner Posted July 27, 2007 Share Posted July 27, 2007 you need to create an array from each result set I suspect you are doing someting like... <?php $result = mysql_query('SELECT...'); $isaresult = mysql_query('SELECT...'); $mergedresult = array_merge($result, $isaresult); ?> If so you have missed out the array formation... <?php $result = mysql_query('SELECT...'); $isaresult = mysql_query('SELECT...'); $resultarr = array(); while($row = mysql_fetch_assoc($result)) { foreach($row as $key => $val) { $resultarr[$key][] = $val; } } $isaresult = array(); while($row = mysql_fetch_assoc($result)) { foreach($row as $key => $val) { $isaresult[$key][] = $val; } } $mergedresult = array_merge($resultarr, $isaresultarr); ?> the field names present in the two datasest should be the same - otherwise you may give yourself a bit of a headache! Link to comment https://forums.phpfreaks.com/topic/62003-merging-2-mysql-resultant-arrays/#findComment-308711 Share on other sites More sharing options...
chrisfane Posted July 27, 2007 Author Share Posted July 27, 2007 yep, that was exactly what i was doing. thanks for the reply, ill give it a go. Link to comment https://forums.phpfreaks.com/topic/62003-merging-2-mysql-resultant-arrays/#findComment-308787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.