Re: [smesa] multiple records
Hi Shawn,
We can give this a try.
First, you'll need to put this function somewhere on your page. Near the bottom is usually good. It's only used to sort our array.
<?php
function sort_array ($array, $index, $order='asc', $natsort=FALSE, $case_sensitive=FALSE) {
if(is_array($array) && count($array)>0) {
foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index];
if(!$natsort) ($order=='asc')? asort($temp) : arsort($temp);
else {
($case_sensitive)? natsort($temp) : natcasesort($temp);
if($order!='asc') $temp=array_reverse($temp,TRUE);
}
foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key];
return $sorted;
}
return $array;
}
?>
Now, near the top, we're going to use this code:
<?php
$tables = array('finance','technology');
$records=array();
$maxRecords = 5;
foreach($tables as $table){
list($tableRecords,$tableMetaData)=getRecords(array(
'tableName' => mysql_escape($table),
'allowSearch' => false,
'limit' => $maxRecords,
'orderBy' => "createdDate desc",
));
foreach($tableRecords as $tableRecord){
$records[]=$tableRecord;
}
}
$records=sort_array($records,'createdDate','desc');
?>
The variable $maxRecords you set to the maximum number of records you want to display. The variable $tables is a list of the tables you want to select from (this can be as many as you want). The code will select the maximum number of records from each table and put them into the array. Finally, it will use our sorting function to order these by the date they were created (newest first).
To output these records, we can use code that looks like this:
<?php $count=0; ?>
<?php foreach($records as $record): ?>
<?php if($count==$maxRecords){
break;
}
else{
$count++;
}?>
*YOUR OUTPUT CODE*
<?php endforeach ?>
This can be used to output the first $maxRecords from our array.
Give this a try and let me know how it works out for you.
Hope it helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/