Re: Basic Dual Query Combine into one question
| From: | Christoph Becker | Date: | Fri, 30 Jan 2015 00:29:23 +0000 |
| Subject: | Re: Basic Dual Query Combine into one question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324323@lists.php.net to get a copy of this message | ||
dealTek wrote:
> my fmstudio code query looks something like this...
>
> ---------------------------
>
> .... query lines then
>
> ends with this
> $test_result = $test_find->execute();
>
>
> then i loop thru like this
>
>
>
> <?php foreach($test_result->getRecords() as $test_row){ ?>
> <tr>
> <td>
>
> <?php echo $test_row->getField('Client_ID'); ?>
> <?php echo $test_row->getField('Contact_First'); ?>
> <?php echo $test_row->getField('Contact_Last'); ?>
> </td>
> <td> </td>
> <td> </td>
> <td> </td>
> </tr>
> <?php } ?>
>
>
> Q: I am confused:
>
> 1 - HOW DO I RE-SORT THIS BEFORE THE LOOP DISPLAY = $test_result ?????
Assuming that $test_result->getRecords() returns an array[1], you could
do the following:
<?php
$records = $test_result->getRecords();
// sort by last name
usort($records, function ($a, $b) {
return strcmp(
$a->getField('Contact_Last'),
$b->getField('Contact_Last')
);
});
?>
<?php foreach ($records as $test_row) { ?>
<!-- the rest as before -->
--
Christoph M. Becker