Merging records and displaying desired fields

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 26, 2011   (RSS)

By Tim_cmsb - July 20, 2011

Hi,

I wanted to merge information of several records together and display them randomly in columns and if possible 5 to 10 newest of each record.
I'm using uploads (jpg) and some text information. See the following page: http://www.vigilantekorsou.com/columns_of_images_of_multiple_tables_tim_new.php .
I want to be able to show the quantity of records I wish. Now I'm getting the same records to show information and when there is no upload I get an empty spot!!!!

These are the records I want to merge and use fields from:

$polisialRecords
$politikaRecords
$hustisiaRecords
$lokalRecord
$internashonalRecords
$arubaRecord
$st_martinRecords
$sosialRecords
$farandulaRecords
$deporte_nashonalRecords
$deporte_internashonalRecords
$titularnanRecords
$notisia_di_ultimo_oraRecords

I used the following in top of the page between <!-- CMSB Records --> and <!-- /CMSB Records -->.
Between the <!-- Line maximum charaters --> and <!-- /Line maximum charaters --> is used to display a number of characters.

<!-- CMSB Records -->
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('D:/Webs/vigil8/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($polisialRecords, $polisialMetaData) = getRecords(array(
'tableName' => 'polisial',
//'orderBy' => 'createdDate DESC',
'orderBy' => 'RAND()',
//'perPage' => '1',
//'limit' => '1',
));

// load records
list($politikaRecords, $politikaMetaData) = getRecords(array(
'tableName' => 'politika',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($hustisiaRecords, $hustisiaMetaData) = getRecords(array(
'tableName' => 'hustisia',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($lokalRecords, $lokalMetaData) = getRecords(array(
'tableName' => 'lokal',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($internashonalRecords, $internashonalMetaData) = getRecords(array(
'tableName' => 'internashonal',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($arubaRecords, $arubaMetaData) = getRecords(array(
'tableName' => 'aruba',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($st_martinRecords, $st_martinMetaData) = getRecords(array(
'tableName' => 'st_martin',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($sosialRecords, $sosialMetaData) = getRecords(array(
'tableName' => 'sosial',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($farandulaRecords, $farandulaMetaData) = getRecords(array(
'tableName' => 'farandula',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($deporte_nashonalRecords, $deporte_nashonalMetaData) = getRecords(array(
'tableName' => 'deporte_nashonal',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($deporte_internashonalRecords, $deporte_internashonalMetaData) = getRecords(array(
'tableName' => 'deporte_internashonal',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($videoRecords, $videoMetaData) = getRecords(array(
'tableName' => 'video',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($titularnanRecords, $titularnanMetaData) = getRecords(array(
'tableName' => 'titularnan',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($notisia_di_ultimo_oraRecords, $notisia_di_ultimo_oraMetaData) = getRecords(array(
'tableName' => 'notisia_di_ultimo_ora',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($avisoRecords, $avisoMetaData) = getRecords(array(
'tableName' => 'aviso',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($aviso_ekonomikoRecords, $aviso_ekonomikoMetaData) = getRecords(array(
'tableName' => 'aviso_ekonomiko',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

// load records
list($partisipashon_di_mortoRecords, $partisipashon_di_mortoMetaData) = getRecords(array(
'tableName' => 'partisipashon_di_morto',
'orderBy' => 'RAND()',
//'limit' => '1',
//'perPage' => '1',
));

foreach($notisia_di_ultimo_oraRecords as $recordMerge) {
$record['titulo'] = $recordMerge['titulo'];
$record['imagen'] = $recordMerge['imagen'];
}
unset($recordMerge);

//////////////////////////// Load Multiple Records Array ///////////////////////
$TimMerge = array();
$TimMerge = array_merge($polisialRecords, $politikaRecords, $hustisiaRecords, $lokalRecords, $internashonalRecords, $arubaRecords, $st_martinRecords, $sosialRecords, $farandulaRecords, $deporte_nashonalRecords, $deporte_internashonalRecords, $titularnanRecords, $notisia_di_ultimo_oraRecords);
// after all records are merged, limit to 6 perPage
$TimMergeRecords = array_slice($TimMerge, 0, 12);

?>
<!-- /CMSB Records -->

<!-- Line maximum charaters -->
<?PHP function textLimit($string, $length, $replacer = '...')
{
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($your_field, 0, $length)) . $replacer;

return $string;
}
?>
<!-- /Line maximum charaters -->

This is the script in the body:

<!-- Pictures in columns box -->
<table style="width: 300px; border-width: 0" cellpadding="0" cellspacing="0">
<tr style="height: 1px">
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="width: 1px; background-color: #D1D2D4; height: 10px;"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="width: 10px; height: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="height: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="height: 10px; width: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="width: 1px; background-color: #D1D2D4; height: 10px;"><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="width: 1px; background-color: #D1D2D4; "><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="width: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="width: 100%; background-color: #F6F6F6; font-size: medium; font-family: Arial, Helvetica, sans-serif; font-weight: 700;">Di tur un tiki</td>
<td style="width: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="width: 1px; background-color: #D1D2D4; "><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="width: 1px; background-color: #D1D2D4; height: 10px;"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="width: 10px; height: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="height: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="height: 10px; width: 10px; background-color: #F6F6F6;"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="width: 1px; background-color: #D1D2D4; height: 10px;"><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="width: 1px; background-color: #D1D2D4; "><img src="images/pixel.gif" width="1" height="1" /></td>
<td colspan="3" valign="top"><img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /><?php if ($TimMergeRecords): ?>

<!-- Images Columns -->
<table width="10%" border="0" align="center" cellpadding="0">
<tr>

<?php shuffle($TimMergeRecords); $count=0; foreach ($TimMergeRecords as $recordMerge): ?>

<td align="center" width="50%">
<table border="0" align="center" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
<tr>
<td align="center" background="#000FFF" valign="top">

<!-- Show if upload or not --><?php if (sizeof($recordMerge['imagen']) >= 1): ?>

<!-- Column stuff-->
<table style="width: 132px; border-width: 0; background-color: #F6F6F6; " cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="text-align: left">

<table style="border-width: 0px; width: 100%; text-align: center; height: 119px; background-color: #FFFFFF;" cellpadding="2" cellspacing="0">
<tr>
<td style="border-width: 0px; text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: small; height: 99px; " valign="top">

<?php foreach ($recordMerge['imagen'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $recordMerge['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath3'] ?>" title="Klek pa mas..." height="99px" width="132px" style="border-style: solid; border-width: 1px" /></a>
<?php break ?>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?><a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>

<?php if (!$recordMerge['imagen']): ?>
<!-- nada -->
<?php endif; ?>


</td>
</tr>
<tr>
<td style="border: 0px solid #FFFFFF; text-align: center; font-family: Arial, Helvetica, sans-serif; font-size: small; height: 20px;" valign="top">

<a href="<?php echo $recordMerge['_link'] ?>" class="underlineclass" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><?PHP echo textLimit($recordMerge['titulo'], 28) ?></a>

</td>
</tr>
</table>

</td>
</tr>
</table>
<!-- /Column stuff -->

<?php else: ?><?php endif ?><!-- /Show if upload or not -->

</td>
</tr></table>
</td>
<?php $maxCols=2; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

<?php endforeach ?>
</tr>
</table>
<!-- /Images Columns -->

<?php else: ?>

<table style="width: 100%; border-width: 0" cellpadding="0" cellspacing="0">
<tr>
<td style="text-align: center">
<a style="color: #ED1C24; font-family: Arial, Helvetica, sans-serif; font-size: medium; font-weight: 700;">No tin nada den database!</a>
</td>
</tr>
</table>

<?php endif ?>

<img src="images/pixel.gif" width="1" height="1" style="height: 10px; width: 10px" /></td>
<td style="width: 1px; background-color: #D1D2D4; "><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
<td style="background-color: #D1D2D4"><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
<tr>
<td style="width: 1px; background-color: #D1D2D4; "><img src="images/pixel.gif" width="1" height="1" /></td>
</tr>
</table>
<!-- /Pictures in columns box -->

I sure whish someone could help me with this.

I've attached e "table and fields that may be used.txt" file with the records and fields used that may be used.

Regards,

Tim

Re: [Jason] Merging records and displaying desired fields

By Tim_cmsb - July 22, 2011

Jason,

I'm still getting the empty spaces...!
I'm working with columns!!!
And the shuffle is not going through all the records.

Regards,

Tim

Re: [Tim_cmsb] Merging records and displaying desired fields

By Jason - July 26, 2011

Hi Tim,

I took a look at the page and it seems like the shuffle is working, since the order of the records change as you refresh the browser. Here are some changes you can try.

First, remove this line:
$TimMergeRecords = array_slice($TimMerge, 0, 12);

We can control the number of records being output using a counter.

Then, make these changes:

<?php $maxCount = 6; ?>
<?php shuffle($TimMerge); $count=0; foreach ($TimMerge as $recordMerge): ?>
<?php if (!$recordMerge['imagen']) { continue; } ?>
<?php if ($count == $maxCount) { break; } ?>
<?php $count++ ;?>


Finally, change the code that controls the columns like this:

<?php $maxCols=2; if (@$count % $maxCols == 0): ?></tr><tr><?php endif; ?>

Hope this 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/