Hi Dave,
I hv the following code on sidebar and it is very long list. How can i change to dropdown list.
<?php
$sql = "SELECT DISTINCT(merchant) as merchant FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";
if (database_querySelect($sql,$rows))
{
foreach($rows as $row)
{
if ($config_useRewrite)
{
$href = $config_baseHREF."merchant/".tapestry_hyphenate($row["merchant"])."/";
}
else
{
$href = $config_baseHREF."search.php?q=merchant:".urlencode($row["merchant"]).":";
}
print "<a href='".$href."'>".$row["merchant"]."</a><br />";
}
}
?>
thanks
jack
Hi David,
I hv upload the script which display the list of merchants inside the box but when i select a particular merchant n click "GO" it doesn't go to the said merchant instead stay at main page.
Wonder what is the problem.
regards,
jack
Hello David,
I hv change the below
print "<form method='GET' action='".$config_baseHREF.".search.php' />";
to
print "<form method='GET' action='".$config_baseHREF."search.php' />";
remove "." in search.php
And now i can select the merchant and hit the "go" button but it appears product search results 0
Hello Jack,
Can you post a link to your site (I will remove the link before I publish your reply) so that I can take a look for you....
Cheers,
David.
Hello David,
My site is {link saved}. Some merchants can some merchants cannot.
regards
jack
Hello Jack,
Ooops - the way it is working the merchant name is getting URL encoded twice! It is only the ones without any spaces that work at the moment. To fix this, change this line:
$value = "merchant:".urlencode($row["merchant"]).":";
to:
$value = "merchant:".$row["merchant"].":";
Cheers,
David.
Hello Jack,
Yes - for simple select boxes just copy the code but change merchant <> brand OR category and it will all work the same!
Making the select boxes change content based on the value of the other boxes is quite complex but I have worked on something similar before - I'll look at posting the code shortly but it's not in a supportable state at the moment!
Cheers,
David.
hi david,
the script above worked for merchant, can i also use the similar code to show category and brand?
i tried editing the merchant words on the script above but i only get a blank dropdown form.
and is it possible to remove the Go button and replace the form with a pull and go feature without the need to click on a go button.
I am also using friendly URLs so url friendly code would be best.
thanks in advance.
Hi,
The modifications for category and brand should be as follows; and i've included a bit of JavaScript to auto-submit which should remove the need for the Go button...
<?php
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
if (database_querySelect($sql,$rows))
{
print "<form method='GET' action='".$config_baseHREF."search.php' />";
print "<select name='q' onchange='JavaScript:this.submit();'>";
foreach($rows as $row)
{
$value = "category:".$row["category"].":";
print "<option value='".$value."'>".$row["category"]."</option>";
}
print "</select>";
print "</form>";
}
?>
...and brand:
<?php
$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
if (database_querySelect($sql,$rows))
{
print "<form method='GET' action='".$config_baseHREF."search.php' />";
print "<select name='q' onchange='JavaScript:this.submit();'>";
foreach($rows as $row)
{
$value = "brand:".$row["brand"].":";
print "<option value='".$value."'>".$row["brand"]."</option>";
}
print "</select>";
print "</form>";
}
?>
It's not that straight forward to submit a form directly to a search engine friendly URL; now it is possible with a redirect at the top of search.php and a hidden field in this form to tell search.php to redirect to the search engine friendly version; but remember that these pages are only ever going to be visited by human users (not search engines); but if you still want to do the redirect let me know and i'll show you what's required...
Cheers,
David.
Hello Jack,
Without JavaScript, or any modifications to other files, this is most easily done as follows:
<?php
$sql = "SELECT DISTINCT(merchant) as merchant FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";
if (database_querySelect($sql,$rows))
{
print "<form method='GET' action='".$config_baseHREF."search.php' />";
print "<select name='q'>";
foreach($rows as $row)
{
$value = "merchant:".$row["merchant"].":";
print "<option value='".$value."'>".$row["merchant"]."</option>";
}
print "</select>";
print "<input type='submit' value='Go' />";
print "</form>";
}
?>
Hope this helps!
Cheers,
David.