You are here:  » Drop Down for...

Support Forum



Drop Down for...

Submitted by Eddie on Tue, 2006-02-14 19:20 in

I am trying to work out how to make 2 drop down menu's for the Brand and Category.

I know how to do drop downs and I understand tha code but I cant get them to combine.

Any ideas ?

Submitted by support on Tue, 2006-02-14 19:25

This code would create a drop down of all brands:

<?php
$sql 
"SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER by brand";
database_querySelect($sql,$rows);
print 
"<select name='brand'>";
foreach(
$rows as $row)
{
  print 
"<option value='".$row["brand"]."'>".$row["brand"]."</option>";
}
print 
"</select>";
?>

Submitted by Eddie on Tue, 2006-02-14 19:57

print " form name='myform' action='brand/".str_replace(" ","-",$feed["brand"])."' method='POST' ";

What have i done wrong ? ( i have removed the to post the code!)

Submitted by support on Tue, 2006-02-14 20:10

Eddie - you can use the code tags use (without the spaces) or just paste PHP include the the PHP tags. When making a post, look at the bullet points alongside the "Filtered HTML" option...

Anyway; if you want to submit the form containing the drop down to the search engine friendly URL you will need to do some JavaScript wizardry. I would start by getting it working with a straight forward GET submit to the search.php script. Here's a complete script to get you started - place this in the top level directory of your Price Tapestry site so that the path to the include files is correct; then start modifying it to your needs:

<?php
require("includes/common.php");
require(
"includes/database.php");
require(
"includes/header.php");
print 
"<form action='search.php' method='GET'>";
$sql "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER by brand";
database_querySelect($sql,$rows);
print 
"<select name='q'>";
foreach(
$rows as $row)
{
  print 
"<option value='brand:".$row["brand"].":'>".$row["brand"]."</option>";
}
print 
"</select>&nbsp;";
print 
"<input type='submit' value='Go' />";
print 
"</form>";
require(
"includes/footer.php");
?>

Submitted by Eddie on Tue, 2006-02-14 20:32

oopss my fault

Submitted by Eddie on Tue, 2006-02-14 20:47

I keep getting : Terminated request because of suspicious input data.

So for the category shouldnt it be:

print "form action='http://www.shopsort.co.uk/Shop/search.php' method='GET'>";
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
database_querySelect($sql,$rows);
print "<select name='q'>";
foreach($rows as $row)
{
  print "<option value='Category:".$row["category"].":'>".$row["category"]."</option>";
}
print "</select>&nbsp;";
print "<input type='submit' value='Go' />";
print "</form>";

Submitted by support on Tue, 2006-02-14 20:52

it should be lowercase "c" in the search string, not "Category", in other words you want:

print "<option value='category:".$row["category"].":'>".$row["category"]."</option>";

Submitted by Eddie on Tue, 2006-02-14 21:26

Ty got that working !

Submitted by clare on Sat, 2007-10-27 18:47

Hi,
I have been trying to make a dropdown selection, but with urls instead of search queries. I have put the code I have been trying to change below and I think that the one line I am not getting right is

print "<option value='$url'>".$row["category"]."</option>";

Where I am trying to make the value equal the category url declared

$url = $baseUrl."category/".urlencode(str_replace(" ","-",$row["category"])).".html";

Is this possible,and if so is there an error in what I am doing.

<html>
<head>
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<?php
print "<form name='form' id='form'>";
    $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
    database_querySelect($sql,$rows);
    print "<select name='jumpMenu' id='jumpMenu' onchange='MM_jumpMenu('parent',this,1)'>";
    foreach($rows as $row)
    $url = $baseUrl."category/".urlencode(str_replace(" ","-",$row["category"])).".html";
   print "<option value='$url'>".$row["category"]."</option>";
    print "</select>&nbsp;";
print "<noscript><input type='submit' value='Submit'></noscript>";
print "</form>";
?>
</body>
</html>

Submitted by clare on Sat, 2007-10-27 20:47

Actually I got the select list showing all the urls now using

<?php
print "<form name='form' id='form'>";
    $sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
    database_querySelect($sql,$rows);
    print "<select name='jumpMenu' id='jumpMenu' onchange='MM_jumpMenu('parent',this,1)'>";
    foreach($rows as $row)
{
   print "<option value='http://www.hairstylezone.com/christmas-gifts-uk/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
}
    print "</select>&nbsp;";
print "<noscript><input type='submit' value='Submit'></noscript>";
print "</form>";
?>

Its not auto submitting yet, but I think thats the js, but I got it listing the urls ok as above, in the dropdown box.

Submitted by support on Sun, 2007-10-28 05:15

Hi Clare,

The URLs in your second block of code look correct. In your first block, you are using .html on the end which only applies to product URLs. Let me know if you still need a hand with the JavaScript...

Cheers,
David.

Submitted by clare on Sun, 2007-10-28 08:20

Hi
This is the final working code I used, as there were a couple of mistakes in what I put above...just in case anyone else is ever doing similar..

<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<?php
print "<form name='form' id='form'>";
    print "<select name='jumpMenu' id='jumpMenu' onchange=\"MM_jumpMenu('parent',this,1)\">";
print "<option>-- Select Gift Range --</option>";
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER by category";
    database_querySelect($sql,$rows);
    foreach($rows as $row)
{
   print "<option value='http://www.site.com/category/".urlencode(str_replace(" ","-",$row["category"]))."/'>".$row["category"]."</option>";
}
    print "</select>";
print "<noscript><input type='submit' value='Go'></noscript>";
print "</form>";
?>

Submitted by clare on Mon, 2007-11-05 08:52

Do you know how this could be happening...I have checked my config file and it appears to be ok

In USA side of site when I use a link like (such as those in dropdown menus)
hairstylezone dot com/christmas-gifts-usa/category/
or
hairstylezone dot com/christmas-gifts-usa/brand/

The results showing are of the UK installation with the uk/html/header & footer and results and everything, and I just cant see what I have done to cause this to happen. I have looked through the obvious files such as config and all seems ok there, so what other file that I may have messed up, could be causing the usa links to call the uk header and footer?

Submitted by support on Mon, 2007-11-05 09:27

Hi Clare,

If the obvious files look ok (I notice the whole site except for the homepage is UK, products as well - not just header & footer) is anything in your top-level .htaccess causing the rewrite?

What about .htaccess inside /christmas-gifts-usa/? Check that RewriteBase is correct inside that file...

Cheers,
David.

Submitted by clare on Mon, 2007-11-05 09:43

Hi,
Yes whole usa site is showing uk stuff and its odd because htaccess looks ok

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^product/(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/$ merchants.php
RewriteRule ^merchant/(.*)/$ search.php?q=merchant:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^merchant/(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^category/$ categories.php
RewriteRule ^category/(.*)/$ search.php?q=category:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^brand/$ brands.php
RewriteRule ^brand/(.*)/$ search.php?q=brand:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^brand/(.*)/(.*).html$ search.php?q=brand:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]

config is usual

<?php
  $config_title = "Christmas Gifts Hair & Beauty";
  $config_charset = "utf-8";
  $config_baseHREF = "/christmas-gifts-usa/";
  $config_useRewrite = True;
  $config_useRelated = True;
  $config_useTracking = True;
  $config_useJavaScript = True;
  $config_useInteraction = True;
  $config_currencyHTML = "$";
   $config_resultsPerPage = 10;
  $config_databaseServer = "localhost";
  $config_databaseUsername = "********";
  $config_databasePassword = "*******";
  $config_databaseName = "HSZUSAproducts";
  $config_databaseTablePrefix = "hszusa";
?>

And so not sure how its happening, I am thinking that if there is no other obvious file that could be causing it, I better reinstall usa site from scratch, doing one step at time.

Submitted by support on Mon, 2007-11-05 09:45

Hi Clare,

Shouldn't...

RewriteBase /

be...

RewriteBase /christmas-gifts-usa/

Cheers,
David.

Submitted by clare on Mon, 2007-11-05 10:51

Ah.. what I was doing was looking at the htaccess.txt instead of .htaccess and when I realised I see .htaccess was pointing at the uk ... I could kick myself sometimes...

Thanks
Clare