Page 1 of 1
Ajax - how do you pass data via dropdown?
Posted: Mon Nov 26, 2012 10:31 am
by simonmlewis
I know how to pass characters thru 'Ajax' to a PHP file and produce the instant results.
But how do you pass data from a dropdown "<option>" field?
I want to pass around 5 entries thru, so as you make your selection, the results appear and get filtered down.
ie.
Category...min price.... max price.... sortby title... etc.
Re: Ajax - how do you pass data via dropdown?
Posted: Mon Nov 26, 2012 11:02 am
by simonmlewis
Trying to build it.
Posting the Category $cat through first, storing that in a session.
That does work and brings up the items in the selected category.
But when I select a $min value, the session doesn't store $cat as it disappears from the echoed check I've put in here.
Why isn't it storing it - and yes, I do have sessions running as my Category page numbers work, which use sessions.
Code: Select all
<?php
if ($min == NULL) { $min = "0.00";}
if ($max == NULL) { $max = "500.00";}
if(isset($_GET['cat']))
{
$cat = $_GET['cat'];
$_SESSION['cat']=$cat;
} else {
$cat=$_SESSION['cat'];
}
if(isset($_GET['min']))
{
$min = $_GET['min'];
$_SESSION['min']=$min;
} else {
$min=$_SESSION['min'];
}
if(isset($_GET['pricemax']))
{
$pricemax = $_GET['pricemax'];
$_SESSION['pricemax']=$pricemax;
} else {
$pricemax=$_SESSION['pricemax'];
}
if(isset($_GET['order']))
{
$order = $_GET['order'];
$_SESSION['order']=$order;
} else {
$order=$_SESSION['order'];
}
echo "$cat, $min";
include "dbconn.php";
$result = mysql_query ("SELECT * FROM products WHERE category = '$cat' AND (price BETWEEN '$min' AND '$max')")or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($row = mysql_fetch_object($result)){
echo "<div class='cat_prodlistbox'>
<a href='index.php?page=videos&ajax=no&id=$row->id&category=$category&pagenum=$pageNum'>
<img src='images/productphotos/small/$row->photothumb' border='0' style='border: 1px solid #cccccc'/><img src='/images/imageshadow.png' border='0' class='shadowmedium'/></a><div class='cat_producttitle'>$row->title<br/>$row->price</div></div>";
} mysql_free_result($result);
mysql_close($sqlconn);
?>
Re: Ajax - how do you pass data via dropdown?
Posted: Mon Nov 26, 2012 1:56 pm
by Eric!
Why isn't it storing it - and yes, I do have sessions running as my Category page numbers work, which use sessions.
Is this the full script? There's no session_start(). Since you allow both methods for setting the variable value are you sure the page numbers (which I can't readily identify in the script) isn't coming from the URL ajax call?
Re: Ajax - how do you pass data via dropdown?
Posted: Tue Nov 27, 2012 4:25 am
by simonmlewis
Ignore the page numbers as they aren't part of it. I jsut left that there from old code.
The session starts in the route *.php file. And works on the category pages that uses page numbers.
Re: Ajax - how do you pass data via dropdown?
Posted: Tue Nov 27, 2012 4:32 am
by simonmlewis
Oh of course - this is a PHP file of it's own, so needs it's own session_start();.
Trying now. What a silly sod!!
Re: Ajax - how do you pass data via dropdown?
Posted: Tue Nov 27, 2012 2:27 pm
by Eric!
Picky, isn't it?