There's probably a more efficient way, using joins on the initial query, but here's an example of how I do it, cobbled together from all the beautiful people on this forum.
Put this
get_manufacturers.php in the root, noting...
Quote:
$manufacturers_limit = 12;
$manufacturers_sort = "random"; // random, name or orderby
|
Code:
<?php
// PhilJ woz ere
// https://forum.x-cart.com/showthread.php?t=75179&page=2
$manufacturers_limit = 12;
$manufacturers_sort = "random"; // random, name or orderby
//------------------------------------
if ($manufacturers_sort == "random") {
$qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY RAND() LIMIT $manufacturers_limit";
} else if ($manufacturers_sort == "name") {
$qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY manufacturer LIMIT $manufacturers_limit";
} else if ($manufacturers_sort == "orderby") {
$qry = "SELECT * FROM " . $sql_tbl["manufacturers"] . " WHERE avail='Y' ORDER BY orderby LIMIT $manufacturers_limit";
}
$result = db_query($qry);
while ($result_row = db_fetch_array($result)) {
$manufacturers[] = $result_row;
}
if ($manufacturers) {
foreach($manufacturers as $key=> $manufacturer)
$manufacturers[$key]["image_path"] = func_query_first_cell("SELECT image_path FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]);
foreach($manufacturers as $key=> $manufacturer)
$manufacturers[$key]["tmbn_x"] = func_query_first_cell("SELECT image_x FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]);
foreach($manufacturers as $key=> $manufacturer)
$manufacturers[$key]["tmbn_y"] = func_query_first_cell("SELECT image_y FROM $sql_tbl[images_M] WHERE id=".$manufacturer["manufacturerid"]);
}
$smarty->assign("featured_manufacturers",$manufacturers);
?>
In your PHP page...
Code:
if ($active_modules['Manufacturers']) {
include './get_manufacturers.php';
}
Smarty...
Code:
{foreach from=$featured_manufacturers item=m name=m}
<p><a href="manufacturers.php?manufacturerid={$m.manufacturerid}"><img src="{$m.image_path|default:'default_icon.gif'}" alt="{$m.manufacturer}" width="{$m.tmbn_x}" height="{$m.tmbn_y}"></a></p>
{if $m.descr}<p>{$m.descr}</p>{/if}
<p><a href="manufacturers.php?manufacturerid={$m.manufacturerid}">{$m.manufacturer|amp}</a></p>
{if !$smarty.foreach.m.last}<hr>{/if}
{/foreach}