Combining Output from 2 mysql_select Calls?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 24, 2016   (RSS)

By Daryl - August 24, 2016

Hi Perch,

What were the problems when you tried to do it on a normal page?

Regards,

Daryl Maximo
PHP Programmer - interactivetools.com

Hi, Daryl -

I'm using this code on the a normal (front-end) page:

$allRecords = mysql_select('records'," hidden != '1' ");
$allPages = mysql_select('pages'," hidden != '1' ");
$result = array_merge_recursive($allRecords, $allPages);

It works - but my guess is it's a bit heavy. 

Also, I would like to sort the $result alphabetically. The only snag is that records have "titles" and pages have "names"!

:0/

Perch

By Daryl - August 24, 2016

Yes, it will be heavy if both tables have lots of records.

It's a bit tricky to sort a combined multi-dimensional array.
So I'd like to suggest to use mysql_select_query() function, for example:

$urlsAndLinks = mysql_select_query("SELECT CONCAT('./', permalink) AS URL, CONCAT(name,' (Page)') AS LINK from {$GLOBALS['TABLE_PREFIX']}pages
                                    UNION
                                    SELECT CONCAT('?rec=', num) AS URL, CONCAT(name,' (Record)') AS LINK from {$GLOBALS['TABLE_PREFIX']}records
                                    ORDER BY LINK");

Let me know how it goes.

Thanks,

Daryl Maximo
PHP Programmer - interactivetools.com

Ah. You see. A little (intelligent) light in dark places makes all the difference!

:0)