PDA

View Full Version : Problema impostazione tabella per stampare una query


findingnerd
26-02-2011, 10:07
Avrei un problemino col php, spero ci sia qualcuno in grado di illuminarmi!
Dunque, c'è la pagina php che esegue una query che prende tipo foto, titolo descrizione dal database.
Poi viene creata una tabella con cui ad ogni ciclo si aggiunge una riga con quei dati suddivisi in colonne.
Io voglio fare questa stessa cosa però in una griglia dove c'è la tabella, per ogni riga ad esempio 4 colonne. In ogni colonna foto descrizione e titolo insieme. Ma facendo così ovviamente l'immagine è uguale per tutte e 4 le colonne.. che potrei fare? Mi serve un risultato tipo questo alla fine: http://www.vintagerollsroycecars.com/

black_wizard
26-02-2011, 12:20
sinceramente non capisco il problema.
incolla il tuo codice dove genera la griglia.

findingnerd
26-02-2011, 12:29
<?php
/**
* @version 1.5
* @package VehicleManagerTop
* @copyright 2009 OrdaSoft
* @author 2009 Sergey Drughinin-OrdaSoft(Sergey.dru@gmail.com)
* @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 &amp; with & as the router doesn't understand &amp;
$url = str_replace('&amp;', '&', $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&amp;task=view&amp;id="
.$row->id."&amp;catid=".$row->catid."&amp;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.":&nbsp;</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 "&nbsp;"; } ?>
</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 "&nbsp;";
}
?>
</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!