Hi David,
I have all of my brands listed in a table on the left of my page as follows.
<?php
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
if (database_querySelect($sql,$rows))
{
foreach($rows as $row)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."brand/".tapestry_hyphenate($row["brand"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=brand:".urlencode($row["brand"]).":";
}
print "<a href='".$href."'>".$row["brand"]."</a><br />";
}
}
?>
So Currently have
Brand1
Brand2
Brand3
Brand4
Trying to save space so wondering if its possible to list the brands in 2 columns within this table, having
Brand1 Brand3
Brand2 Brand4
Any ideas?
Thanks
Adrian
Hi David,
Thanks for that, works great :)
Cheers
Adrian
Hi David,
Do you know is there anyway to exclude a certain brand from being displayed. Lets say the above code displys
Sony
Canon
Fuji
Panasonic
Is there anyway I could just disokay Canon and Fuji and leave out the other 2 brands?
Thanks
Adrian
Hi Adrian,
Sure - you can just skip each loop iteration conditionally. Where you have:
foreach($rows as $row)
{
..replace this with:
foreach($rows as $row)
{
if (
$row["brand"]=="Sony"
||
$row["brand"]=="Panasonic"
) continue;
Cheers,
David.
Thanks David,
If I had a large number of brands and still only wanted to display two brands, is there anyway I could specify which brands to include rather that the brands to be excluded?
Thanks
Adran
Hi Adrian,
Assuming that you need to be sure products for those brands exist in the database (otherwise it could be done without any database code of course) - then the SQL could be changed as follows:
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE BRAND IN ('Canon','Fuji') ORDER BY brand";
(and you wouldn't need any other mod, so could undo the code version described above)
Cheers,
David.
Hi Adrian,
Have a go with this;
<?php
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
if (database_querySelect($sql,$rows))
{
print "<table border='0'>";
print "<tr>";
$column = 0;
foreach($rows as $row)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."brand/".tapestry_hyphenate($row["brand"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=brand:".urlencode($row["brand"]).":";
}
print "<td><a href='".$href."'>".$row["brand"]."</a></td>";
$column++;
if ($column==2)
{
print "</tr>";
print "<tr>";
$column = 0;
}
}
print "</tr>";
print "</table>";
}
?>
Cheers,
David.