Ajax - how do you pass data via dropdown?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Ajax - how do you pass data via dropdown?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Ajax - how do you pass data via dropdown?

Post 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);
?>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Ajax - how do you pass data via dropdown?

Post 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?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Ajax - how do you pass data via dropdown?

Post 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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Ajax - how do you pass data via dropdown?

Post 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!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Ajax - how do you pass data via dropdown?

Post by Eric! »

Picky, isn't it?
Post Reply