<?php
/**
* @version 1.5
* @package VehicleManagerTop
* @copyright 2009 OrdaSoft
* @author 2009 Sergey Drughinin-OrdaSoft(
[email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @description VehicleTop for VehicleManager Component
*/
/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Restricted access' );
$database = &JFactory::getDBO();
if( !function_exists( 'sefreltoabs')) {
function sefRelToAbs( $value ) {
//Need check!!!
// Replace all & with & as the router doesn't understand &
$url = str_replace('&', '&', $value);
if(substr(strtolower($url),0,9) != "index.php") return $url;
$uri = JURI::getInstance();
$prefix = $uri->toString(array('scheme', 'host', 'port'));
return $prefix.JRoute::_($url);
}
}
//Common parameters
$sort_top_by = $params->def('sort_by_top', 0); //Get how to sort the top items
$show_published = $params->def('only_published', 1); //Get if we only show published items
$show_covers = $params->def('covers', 0 ); //Get if we Real Estate photos
$cover_height = $params->def('cover_height', "50"); //Get Real Estate photos
$show_extra = $params->def('extras', 1 ); //Get if we show second column with additional info
$show_ranking = $params->def('ranking', 0 ); //Get if we show the ranking next to them
$showprice = $params->get ('price', 1);
//Individual parameters
$count_vehicle= intval($params->def('books',1));
//Definition of Sorts
switch($sort_top_by)
{
case 0:
$sql_sort_top = "hits";
break;
case 1:
$sql_sort_top = "date";
break;
// case 2:
// $sql_sort_top = "rating";
// break;
}
//Check if only display published items
if ($show_published==1) {
$sql_published = "WHERE published=1";
} else {
$sql_published = "";
}
if($count_vehicle!='' && $count_vehicle!=0) {
$selectstring = "SELECT vtitle,id,image_link,hits,catid,price FROM #__vehiclemanager_vehicles "
.$sql_published." ORDER BY ".$sql_sort_top." DESC LIMIT 0, $count_vehicle;";
$database->setQuery($selectstring);
$rows_vehicle= $database->loadObjectList();
}
$selectstring = "SELECT id FROM #__menu WHERE link='index.php?option=com_vehiclemanager'";
$database->setQuery($selectstring);
$ItemId_tmp = $database->loadResult();
function DisplayVM($rows, $name, $show_ranking, $show_covers, $show_extra, $cover_height, $ItemId_tmp,$showprice) {
$rank_count = 0;
$span=0;
if($show_ranking!=0) $span++;
if($show_covers!=0) $span++;
if($show_extra!=0) $span++;
?>
<table cellpadding="0" cellspacing="0" class="moduletable" width="100%" border="1">
<?php foreach ($rows as $row) {
$rank_count = $rank_count + 1; //start ranking
$link1 ="index.php?option=com_vehiclemanager&task=view&id="
.$row->id."&catid=".$row->catid."&Itemid=".$ItemId_tmp;
$imageURL = $row->image_link ;
if($imageURL != '' && substr($imageURL,0,4) != "http")
{
$imageURL = "./components/com_vehiclemanager/photos/".$row->image_link;
}
if($imageURL == ''){
$imageURL = "./components/com_vehiclemanager/images/no-img_eng.gif";
}
?>
<tr>
<?php if($show_ranking==1) { echo "<td>".$rank_count.": </td>"; } //Add Column for Ranking if param set ?>
<?php if ($show_covers==1) {?>
<td>
<img src="<?php echo $imageURL; ?>" width="200" alt="<?php echo $row->vtitle; ?>" hspace="2" vspace="2" border="0" /> <br /> <a href="<?php echo sefRelToAbs( $link1 ); ?>" target="_self""><?php echo $row->vtitle; ?></a> <br /> <?php if ($showprice == "1") { echo "Prezzo: ".$row->price; } else { echo " "; } ?>
</td>
<?php } ?>
<td width="160" <?php if($span!=0) echo "colspan='$span'";?>>
<a href="<?php echo sefRelToAbs( $link1 ); ?>" target="_self""><?php echo $row->vtitle; ?></a>
<?php
if ($showprice == "1") {
echo "<br />".$row->price;
} else {
echo " ";
}
?>
</td>
<?php if($show_extra==1) {?>
<td align="right">
<font class='small'>(<?php echo $row->hits; ?>)</font>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
<?php
@include "config.php";
$colonne = 2;
$sql = "SELECT vtitle,id,image_link,hits,catid,price FROM #__vehiclemanager_vehicles ";
$res = @mysql_query($sql);
$vtitle = $resrow[0];
$id = $resrow[1];
$image_link = $resrow[2];
$hits = $resrow[3];
$catid = $resrow[4];
$price = $resrow[5];
if(($righe = @mysql_num_rows($res))>0)
{
echo "<table>\n";
for($i = 0; $i < $righe; $i++) {
$r = @mysql_fetch_array($res);
if($i % $colonne == 0) {
echo "<tr>\n";
}
echo "<td>" . $vtitle . "</td>\n";
if(($i % $colonne) == ($colonne - 1) || ($i + 1) == $righe) {
echo "</tr>\n";
}
}
echo "</table>\n";
}
?>
<?php
}
?><?php
if(count($rows_vehicle)) { DisplayVM($rows_vehicle, "Top Vehicles", $show_ranking, $show_covers, $show_extra,$cover_height, $ItemId_tmp,$showprice); }
?>
Questo è il codice del modulo (il sito è basato su joomla) che sto utilizzando, ma li mostra in modo verticale e a me servirebbe una griglia. Ho trovato riferimenti qui http://www.claudiogarau.it/php/Incolonnamento_dei_records_MySQL_ordinamento_orizzontale_e_verticale.php ma le query sono diverse di come le manda joomla!