PDA

View Full Version : Recordset Filter


player3612
04-10-2006, 05:23 PM
Hi all this is my first post so I hope it is in the right place.

I have created a record set that filters by size, for e.g. 2ft 6, 3ft 0, 4ft 6 etc, depending on the size you click. This then displays a results page of all products in the 2ft 6 size if that is the link that is clicked.

The problem that I have is that this results page also displays other fields like Manufacturer, Type etc that I would like to further filter by. What I would like to be able to do is maybe have a drop down above the Manufacturer or Type Header that will allow me to select a Manufacturer and my list will then be filtered by the 2ft 6 and the Manufacturer selected from the drop down.

I am using PHP and Mysql so if anyone could help me or point me in the right direction it would be much appreciated. Maybe there is an extension or something that I could use. I am new to a lot of this so don't know how to write the code which is why I mention the extension.

Thanks in advance
Phil

davidj
04-11-2006, 07:29 AM
please post code from both pages

player3612
04-11-2006, 08:04 PM
Hi,
I am not sure where to start here but to give you an idea of what I want to achieve I have a link that will show you. http://www.mattressman.co.uk/list.asp?MMsize=MM2foot6&cat=all

You will see that the list is filtered from the size option to the left and then when you hover your mouse over the main headers a menu appears so that you can further filter the table by the choice you select. I know this is done on an asp page but I would like to do the same on my php page.

How this is achieved I don't mind, either a drop down box or the menu as shown in the example site. I don't have much to show as I have not built the site yet other than put the database together and start on some test pages to try and achieve the required results.

Here is some code on the results page that I have been trying to get working but failed. As you will see this is a javascript menu that I have got from Dynamic Drive and tried to change the menu 1 array to include my recordset, I did have the rest of the code there that should have loaded all the products into the list but it did not work so I removed it.

<script type="text/javascript">

/***********************************************
* AnyLink Drop Down Menu- Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1

var menu1=new Array()
menu1[0]='<?php echo $row_rsMattresses_bysize['name_prd']?> (../../mattresses_bysize.php?select1=<?php echo $row_rsMattresses_bysize['name_prd']; ?>)'

//Contents for menu 2, and so on
var menu2=new Array()
menu2[0]='CNN (http://cnn.com)'
menu2[1]='MSNBC (http://msnbc.com)'
menu2[2]='BBC News (http://news.bbc.co.uk)'

var menuwidth='165px' //default menu width
var menubgcolor='lightyellow' //menu bgcolor
var disappeardelay=250 //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWid th-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeig ht-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeigh t
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHe ight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)

dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

</script>

This is a part of the script that is inserted in the <body> depending where you want the menu.

<td>

Product (default.htm)</td>

If there is a tutorial or something that explains how to do this that would be great. I don't know how to insert the php into the javascript.

Thanks in advance
Phil

davidj
04-12-2006, 07:34 AM
please post your PHP code

this is javascript

player3612
04-12-2006, 05:26 PM
Hi David,
I know this is javascript that is what I am trying to use to create my menu. You will notice that there is a php echo function in there and some db values but this is not complete which is what my problem is as this only calls one value and I don't know how to go any further with it.

Anyway here is all the results page code, please remember this is just a test page.

<?php

// Load the common classes
require_once('includes/common/KT_common.php');


//MX Widgets3 include
require_once('includes/wdg/WDG.php');

$KTColParam1_rsMattresses_bysize = "0";
if (isset($_GET["select1"])) {
$KTColParam1_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_GET["select1"] : addslashes($_GET["select1"]);
}
$KTColParam2_rsMattresses_bysize = "0";
if (isset($_GET["RecordID"])) {
$KTColParam2_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_GET["RecordID"] : addslashes($_GET["RecordID"]);
}
$KTColParam3_rsMattresses_bysize = "0";
if (isset($_GET["PriceID"])) {
$KTColParam3_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_GET["PriceID"] : addslashes($_GET["PriceID"]);
}
mysql_select_db($database_mx_shop, $mx_shop);
$query_rsMattresses_bysize = sprintf("SELECT products_prd.size1_prd, products_prd.id_prd, products_prd.name_prd, optionvalue_ova.name_ova, products_prd.price_prd, optionvalue_ova.id_ova, productoption_pop.idprd_pop, productoption_pop.id_pop FROM ((productoption_pop LEFT JOIN products_prd ON products_prd.id_prd=productoption_pop.idprd_pop) LEFT JOIN optionvalue_ova ON optionvalue_ova.id_ova=productoption_pop.idova_pop ) WHERE products_prd.name_prd='%s' OR optionvalue_ova.name_ova='%s' OR products_prd.price_prd='%s' ORDER BY products_prd.price_prd ASC ", $KTColParam1_rsMattresses_bysize,$KTColParam2_rsMa ttresses_bysize,$KTColParam3_rsMattresses_bysize);
$rsMattresses_bysize = mysql_query($query_rsMattresses_bysize, $mx_shop) or die(mysql_error());
$row_rsMattresses_bysize = mysql_fetch_assoc($rsMattresses_bysize);
$totalRows_rsMattresses_bysize = mysql_num_rows($rsMattresses_bysize);

//initialize the Alternate Color index
$AltColors1 = 0;

//initialize the Alternate Color index
$AltColors2 = 0;

//initialize the Alternate Color index
$AltColors3 = 0;

//initialize the Alternate Color index
$AltColors4 = 0;
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
<!--
.productList {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #CCCCCC;
}
-->
</style>
<style type="text/css">
<!--
a:link {
color: #FF0000;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #9999FF;
}
a:active {
color: #FFFFFF;
}
-->
</style>
<style type="text/css">

#dropmenudiv{
position:absolute;
border:1px solid black;
border-bottom-width: 0;
font:normal 12px Verdana;
line-height:18px;
z-index:100;
}

#dropmenudiv a{
width: 100%;
display: block;
text-indent: 3px;
border-bottom: 1px solid black;
padding: 1px 0;
text-decoration: none;
font-weight: bold;
}

#dropmenudiv a:hover{ /*hover background color*/
background-color: yellow;
}

</style>

<script type="text/javascript">

/***********************************************
* AnyLink Drop Down Menu- Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//Contents for menu 1

var menu1=new Array()
menu1[0]='<?php echo $row_rsMattresses_bysize['name_prd']?> (../../mattresses_bysize.php?select1=<?php echo $row_rsMattresses_bysize['name_prd']; ?>)'

//Contents for menu 2, and so on
var menu2=new Array()
menu2[0]='CNN (http://cnn.com)'
menu2[1]='MSNBC (http://msnbc.com)'
menu2[2]='BBC News (http://news.bbc.co.uk)'

var menuwidth='165px' //default menu width
var menubgcolor='lightyellow' //menu bgcolor
var disappeardelay=250 //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWid th-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeig ht-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeigh t
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHe ight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)

dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu

</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#0000FF">
<td>

Product (default.htm)</td>
<td> <h4></h4>


</td>
<td> <h4></h4>


<font color="#FFFFFF"></font></p></td>
<td> <h4><font color="#FFFFFF"> </font></h4></td>
</tr>
<tr valign="top">
<?php
do { // horizontal looper
?>
<td height="50" bgcolor="<?php echo (((++$AltColors1) % 2) == 0) ? "#9999ff" : "#ccccFF"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['name_prd']; ?> <?php if ($totalRows_rsMattresses_bysize == 0) { // Show if recordset empty ?>
Sorry No Products Found
<?php } // Show if recordset empty ?> </td>
<td height="50" bgcolor="<?php echo (((++$AltColors2) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['price_prd']; ?></td>
<td height="50" bgcolor="<?php echo (((++$AltColors3) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['name_ova']; ?></td>
<td height="50" bgcolor="<?php echo (((++$AltColors4) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout="">

<?php echo $row_rsMattresses_bysize['name_man']; ?></p>


</p></td>
<?php
$row_rsMattresses_bysize = mysql_fetch_assoc($rsMattresses_bysize);
if (!isset($nested_rsMattresses_bysize)) {
$nested_rsMattresses_bysize= 1;
}
if (isset($row_rsMattresses_bysize) && is_array($row_rsMattresses_bysize) && $nested_rsMattresses_bysize++%1==0) {
echo "<tr>";
}
} while ($row_rsMattresses_bysize); //end horizontal looper
?>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsMattresses_bysize);
?>[/code]

davidj
04-13-2006, 07:26 AM
I think i understand now

you want a dynamic dropdown

2 dropdowns.

dropdown1 filters first then you can filter again by using dropdown 2

yes?

player3612
04-13-2006, 11:35 AM
Thats about it David,
The only thing is the dropdowns should be independent. For example, dropdown one will filter all records for a particular manufacturer and list them in a table, then dropdown two will further filter that table by 'type' for example.

I dont need dropdown No two to contain the filtered records from drop down one, each dropdown needs to filter its independent field i.e. Type, Manufacturer and so on.

Thanks again
Phil

davidj
04-13-2006, 12:25 PM
set each dropdown value as a session then filter the recordset using these sessions

player3612
04-13-2006, 01:12 PM
Thanks Dave I will have a play with that when I get home. Is this easy to do or could you give me some tips / guidance or even a tutorial.

Thanks again
Phil

davidj
04-13-2006, 01:56 PM
i will write an example

player3612
04-13-2006, 03:51 PM
Thanks David that will great if you could do that, much appreciated.

Phil

davidj
04-13-2006, 03:53 PM
finished for the weekend so wont be able to post until wednesday

davidj
04-20-2006, 11:14 AM
ok
example....

if you use $_POST to catch your values then use something like this..


$var1 = $_POST['fieldname']; ///// << catch value assign to $var1

$_session['dropdown1'] = $var1; ///<< set session with $var1 value

if (isset($_session['dropdown1'])){ // << check that session is set >>

$filter1 = 'db_field ='."'".$_session['dropdown1']"'"; // << if sess isset build WHERE clause (***db_field is required field for filter ***)

}

now in your select statement...

select * from table where $filter1 /// etc >>
if $filter1 contains a value then it will get executed after the WHERE clause
example...
select * from table where db_field = 'value'

just repeat for any othe filter you require...

player3612
04-20-2006, 11:20 PM
David,
Sorry I am a bit lost, how do I use $_POST to catch my values?
If I am using a form list what name do I need to call the list, at the moment my form looks like this
<form action="/mattresses_bysize.php" method="post">
<table width="160" border="0" cellspacing="1" cellpadding="1" class="nugget">
<tr>
<td nowrap><select name="product_name" id="product_name" title="">
<option value= <?php if (!(strcmp("", $HTTP_SESSION_VARS['POST']))) {echo "SELECTED";} ?>>Choose
One</option>
</select> <input type="submit" name="Submit" value="Go"> </td>
</tr>
</table>
When you say catch the values does this mean load them in the list of the form or just store them in a variable.

Thanks
Phil

davidj
04-21-2006, 07:40 AM
that form does nothing

it contains no values ...
(am i missing something here or cant i see the wood for the trees)

player3612
04-21-2006, 08:32 AM
David,
I would be happy if you were missing something but your not. All this does is gives me my empty list. I want the list to contain the values that have been loaded into my table from the first recordset on the previous page

As you will see from the image, the list should hold the values of the dynamic field below it. There will finally be a list above each field, or at least each filter that I want to further filter by.

The list did get its values from the recordset untill you said it should be done via a session. Maybe I have missunderstood, could you please put me right and tell me how I get the value from my dynamic list into my form list for further filtering.

Thanks
Phil

davidj
04-21-2006, 09:04 AM
ping!!

i think i see the light !!!

you want to know how to dynamicaly populate each dropdown with values for that column

then selecting each dropdown would filter the recordset accordingly

Please say i am right as i am shaking and need a prozac

player3612
04-21-2006, 09:25 AM
That's right, that is exactly what I want.
Sorry I have not explained myself to well I don't mean to waste peoples time.

Thanks
Phil

davidj
04-21-2006, 09:28 AM
err sorry i dont know how to do that !


Just joking hehe ....



post the entire code for that page

player3612
04-21-2006, 09:49 AM
Complete code for page

<?php

// Load the common classes
require_once('includes/common/KT_common.php');


//MX Widgets3 include
require_once('includes/wdg/WDG.php');

$KTColParam1_rsMattresses_bysize = "0";
if (isset($_SESSION["manufacturer"])) {
$KTColParam1_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_SESSION["manufacturer"] : addslashes($_SESSION["manufacturer"]);
}
$KTColParam2_rsMattresses_bysize = "0";
if (isset($_GET["RecordID"])) {
$KTColParam2_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_GET["RecordID"] : addslashes($_GET["RecordID"]);
}
$KTColParam3_rsMattresses_bysize = "0";
if (isset($_GET["PriceID"])) {
$KTColParam3_rsMattresses_bysize = (get_magic_quotes_gpc()) ? $_GET["PriceID"] : addslashes($_GET["PriceID"]);
}
mysql_select_db($database_mx_shop, $mx_shop);
$query_rsMattresses_bysize = sprintf("SELECT DISTINCT products_prd.size1_prd, products_prd.id_prd, products_prd.name_prd, optionvalue_ova.name_ova, products_prd.price_prd, optionvalue_ova.id_ova, productoption_pop.idprd_pop, productoption_pop.id_pop FROM ((productoption_pop LEFT JOIN products_prd ON products_prd.id_prd=productoption_pop.idprd_pop) LEFT JOIN optionvalue_ova ON optionvalue_ova.id_ova=productoption_pop.idova_pop ) WHERE products_prd.name_prd='%s' OR optionvalue_ova.name_ova='%s' OR products_prd.price_prd='%s' ", $KTColParam1_rsMattresses_bysize,$KTColParam2_rsMa ttresses_bysize,$KTColParam3_rsMattresses_bysize);
$rsMattresses_bysize = mysql_query($query_rsMattresses_bysize, $mx_shop) or die(mysql_error());
$row_rsMattresses_bysize = mysql_fetch_assoc($rsMattresses_bysize);
$totalRows_rsMattresses_bysize = mysql_num_rows($rsMattresses_bysize);

$KTColParam1_rsManufacturer = "0";
if (isset($_SESSION["manufacturer"])) {
$KTColParam1_rsManufacturer = (get_magic_quotes_gpc()) ? $_SESSION["manufacturer"] : addslashes($_SESSION["manufacturer"]);
}
mysql_select_db($database_mx_shop, $mx_shop);
$query_rsManufacturer = sprintf("SELECT products_prd.size1_prd, products_prd.id_prd, products_prd.name_prd, optionvalue_ova.name_ova, products_prd.price_prd, optionvalue_ova.id_ova, productoption_pop.idprd_pop, productoption_pop.id_pop FROM ((productoption_pop LEFT JOIN products_prd ON products_prd.id_prd=productoption_pop.idprd_pop) LEFT JOIN optionvalue_ova ON optionvalue_ova.id_ova=productoption_pop.idova_pop ) WHERE products_prd.name_prd='%s' ", $KTColParam1_rsManufacturer);
$rsManufacturer = mysql_query($query_rsManufacturer, $mx_shop) or die(mysql_error());
$row_rsManufacturer = mysql_fetch_assoc($rsManufacturer);
$totalRows_rsManufacturer = mysql_num_rows($rsManufacturer);

//initialize the Alternate Color index
$AltColors1 = 0;

//initialize the Alternate Color index
$AltColors2 = 0;

//initialize the Alternate Color index
$AltColors3 = 0;

//initialize the Alternate Color index
$AltColors4 = 0;
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
<!--
.productList {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #CCCCCC;
}
-->
</style>


</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="#0000FF">
<td>

</td>
<td> <h4></h4>


</td>
<td> <h4></h4>


<font color="#FFFFFF"></font></p></td>
<td> <form action="/mattresses_bysize.php" method="post">
<table width="160" border="0" cellspacing="1" cellpadding="1" class="nugget">
<tr>
<td nowrap><select name="product_name" id="product_name" title="">
<option value= <?php if (!(strcmp("", $HTTP_SESSION_VARS['POST']))) {echo "SELECTED";} ?>>Choose
One</option>
</select> <input type="submit" name="Submit" value="Go"> </td>
</tr>
</table>
</form>
<font color="#FFFFFF"> </font></td>
</tr>
<tr valign="top">
<?php
do { // horizontal looper
?>
<td height="50" bgcolor="<?php echo (((++$AltColors1) % 2) == 0) ? "#9999ff" : "#ccccFF"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['name_prd']; ?> <?php if ($totalRows_rsMattresses_bysize == 0) { // Show if recordset empty ?>
Sorry No Products Found
<?php } // Show if recordset empty ?> </td>
<td height="50" bgcolor="<?php echo (((++$AltColors2) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['price_prd']; ?></td>
<td height="50" bgcolor="<?php echo (((++$AltColors3) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout=""><?php echo $row_rsMattresses_bysize['name_ova']; ?></td>
<td height="50" bgcolor="<?php echo (((++$AltColors4) % 2) == 0) ? "#9999ff" : "#ccccff"; ?>" class="productList" onmouseover="" onmouseout="">

<?php echo $row_rsMattresses_bysize['name_prd']; ?></p>


</p></td>
<?php
$row_rsMattresses_bysize = mysql_fetch_assoc($rsMattresses_bysize);
if (!isset($nested_rsMattresses_bysize)) {
$nested_rsMattresses_bysize= 1;
}
if (isset($row_rsMattresses_bysize) && is_array($row_rsMattresses_bysize) && $nested_rsMattresses_bysize++%1==0) {
echo "<tr>";
}
} while ($row_rsMattresses_bysize); //end horizontal looper
?>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsMattresses_bysize);

mysql_free_result($rsManufacturer);
?>

Thanks
Phil

davidj
04-25-2006, 08:59 AM
you need to dynamicaly create a WHERE clause in your SQL

as you have it....
WHERE products_prd.name_prd='%s' OR optionvalue_ova.name_ova='%s' OR products_prd.price_prd='%s'

you would change to
WHERE '%s' '%s' '%s' , $var1, $var2, $var3

then you would assign each $var depending on what has been selected in your dropdown.

set these values as sessions...

$dropdown1 = $_POST['dropdown1']; // ** this has filter value

$_session['var1'] = $dropdown1; // ** set filter value to a session

$var1 = 'db_field1 ="'.$_session['var1'].'"'; // ** build $var1

/// this will echo out like db_field1 ='1' ///

repeat the above to cover all your filter requests then add them to the new select statement..

WHERE '%s' '%s' '%s' , $_session['var1'], $_session['var2'], $_session['var3']

sunvalley
05-27-2006, 02:56 AM
Hi, I am looking for the same thing but I'm using ASP code. Could you please translate the PHP code into ASP code, thank you very much!

This is what I am working with,

I have two dropdown menus on a search page call Operator and County.
And in the Results page I have one recordset with sql like...
SELECT *
FROM tbl_WellData
WHERE operatorname LIKE 'MMColParam' AND countyname LIKE 'MMColParam1'

I am able to search using both dropdown menus and get results, but I want to be able to also select from just the Operator menu without a County and still get results based on the Operator I selected.

How would I code my recordset to see the search filter of using both One or Two dropdown menus?