[FX.php List] Combine two sets of search results into one table?
Steven Thoms
sthoms at wavecomm.com
Fri Jul 20 16:43:44 MDT 2012
Denis,
You may then want to re-key the arrays and use the ksort() function.
Something like:
$newArray = array();
$i = 0;
foreach ( $array1 as $keys => $record ) {
$i++;
$datekey = date( 'Ymd', $record['dateField']).$i;
// you add the $i var to allow for many records with the same
date and assure a unique set of keys
$newArray[$dateKey] = $record;
}
foreach ( $array2 as $keys => $record ) {
$i++;
$datekey = date( 'Ymd', $record['dateField']).$i;
// you add the $i var to allow for many records with the same
date and assure a unique set of keys
$newArray[$dateKey] = $record;
}
ksort($newArray);
print_r($newArray);
and see what you got.
I hope that helps you out,
Steve
207 798-0171
On Jul 20, 2012, at 3:03 PM, Denis Somar wrote:
> I definitely want to merge the arrays as these are going to be
> sorted by date not by type. I'm gathering what I should be doing is
> using array_merge in PHP.
>
> But even if I do perform array_merge, the FOR loop will essentially
> just see the first part of the array from one table and the next
> half of the array, so I'll likely also have to do some array sorting
> beforehand, right?
>
> Thanks again for the help! Any snippets out there btw?
>
> Best,
> Denis
>
>
>
> On Fri, Jul 20, 2012 at 1:20 PM, Dale Bengston <dale.bengston at gmail.com
> > wrote:
> Yes! Absolutely you can just tack the second set of results to the
> first with another foreach loop. Merging arrays will give you better
> control over knitting the results (re-sorting, for example) if
> that's desired. If not, go easy!
>
> Dale
>
> On Jul 20, 2012, at 9:50 AM, BEVERLY VOTH wrote:
>
> > Denis, you can merge the arrays with PHP
> >
> > OR
> > you can just make one table and put these together on output (that
> is, if you don't need to merge them in some other way with sorts,
> etc.)
> >
> > TABLE
> > foreach (first query results) {
> > TR..
> > }
> > foreach (second query results) {
> > TR..
> > }
> > /TABLE
> >
> > Beverly
> >
> > On 20 Jul 2012, at 10:00 AM, Denis Somar wrote:
> >
> >> This is just for outputs sake. I have two tables Requests and
> Quotes and rather than displaying two separate tables with results I
> was trying to determine if I could show query results from each
> table in one combined HTML table
> >
> > _______________________________________________
> > FX.php_List mailing list
> > FX.php_List at mail.iviking.org
> > http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list