View Single Post
Old 12-09-2012, 06:32 AM   PM User | #1
Prime8
New Coder

 
Join Date: Oct 2010
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
Prime8 is an unknown quantity at this point
PHP + MYSQL filter query results dynamically (without sending back to the server)

Hello, I have a database I am trying to perform some filtering on. The default display is all of the records (working - or was before I tried what I'm about to post), and I have some inputs (drop downs, text fields) I'd like to change the state of and have the results update - hopefully without the use of a submit button. Here's basically what I'm trying to do.

Basic PHP code:
PHP Code:
echo "<th><select name='A' id='A' onChange='" theAFunction() . "'>
<option value='1'>1</option>
<option value='2'>2</option>
</select></th>"
;
echo 
"<th><input type='text' name='B' id='B' onChange='" theBFunction() . "'></input></th>";
.
.
.

$a '%'// Setting the variables to match all the records first
$b '%';
$c '%';
$d '%';

$filter "SELECT * FROM table WHERE aye LIKE '" $a "' AND bee LIKE '" $b "' AND cee LIKE '" $c "' ORDER BY aye";

$result mysql_query($filter);

.
.
.
while (
$row mysql_fetch_array($result))
echo 
"<tr>";
echo 
"<td>" $row[aye] . "</td>";
echo 
"<td>" $row[bee] . "</td>";
echo 
"</tr>";

function 
theAFunction()
{
// trying incorrectly to get the values of the fields as they are changed,
// obviously $_POST doesn't work but this is where my problem is
$a $_POST['A'];
}
function 
theBFunction()
{
$b $_POST['B'];
}
.
.

The above code returns errors on the $_POST lines (to be expected since nothing has been sent to the server).

I'm more used to the javascript DOM, and it seems like I do need to pass the results back to javascript somehow to do this without submitting a form - but then I think I will run in to a problem with getting js to update the query results from the database.

Any help would be appreciated.
Prime8 is offline   Reply With Quote