Ajax(ify) Combox populated by PHP array - php

I'm still learning how Ajax works, and as such I'm having a lot of trouble taking my current PHP combo box, and making it Ajaxified. The combo box choices are populated by a PHP array, and represent the number of images I wish to display on a page. Right now all the code is in one PHP file, although I'm pretty sure when it's in Ajax, it will have to be in two pages.
Oh, and if you could use jQuery, it would be much appreciated.
<?php
$curPage = 0;
if(isset($_GET['page'])){
$curPage = (int) $_GET['page'];
}
// values of combobox in an array
$imgNum_values = array('12','16','20');
if(isset($_GET['imgs']) && in_array($_GET['imgs'], $imgNum_values))
{
$selected_imgNum = $_GET['imgs'];
}else{
// input default value, if empty the first variable will be shown
$selected_imgNum = '';
}
$option_num = count($imgNum_values);
echo '
<form name=imgNum method="get" action="new_arrivals_img.php">
<label>number of images per page:</label>
<select name="imgs" onChange="imgNum.submit();">';
for($x = 0; $x < $option_num; $x++)
{
// print the options
echo '
<option value="'.$imgNum_values[$x].'"'.($imgNum_values[$x] == $selected_imgNum ?
' selected="selected"' : '').'>'.$imgNum_values[$x].'</option>';
}
echo '
</select>
<input type="hidden" name="page" value="<?php echo $curPage; ?>" />
</form>';
?>
Below is the PHP query etc for the images displayed. I don't need the below section changed into Ajax at the moment, unless it's essential to the above code being changed into Ajax.
<?php
if((int) $_GET['imgs'] > 0){
$limit = (int) $_GET['imgs'];
} else {
$limit = 12;
}
$mysql_link = mysql_connect("localhost", "root", "root");
mysql_select_db("new_arrivals_imgs") or die("Could not select database");
$query = mysql_query("SELECT `imgURL`,`imgTitle` FROM `images` ".
"ORDER BY `imgDate` DESC LIMIT " . $limit * $curPage . ", $limit") or die(mysql_error());
if(!$query) {
echo "Cannot retrieve information from database.";
} else {
while($row = mysql_fetch_assoc($query)) {
echo "<li><a href='new_arrivals_img/".$row['imgURL']."' class='gallery' title='".$row['imgTitle']."'><img src='new_arrivals_img/thumbnails/".$row['imgURL']."'></a></li>";
}
}
?>
Thanks so much for any help.

I'll give you an example on how you could do this with jQuery:
The HTML:
<form>
<label>Images Number:</label>
<select id="imgNum" name="imgNum">
<option value="12">12</option>
<option value="16">16</option>
<option value="20">20</option>
</select>
</form>
<div id="imgTray"></div>
The JavaScript(jQuery):
//Bind the onChange event to Fetch images on combox selection
$("#imgNum").change(function(){
//The combo box
var sel = $(this);
//Selected value
var value = sel.value();
//Feth the images
$.get("get_images.php",{imgs: value}, function(data){
//Add images(or what ever the script output is) to the document
$("#imgTray").html(data);
});
})
//You should store the current selected option in a cookie
//For the sake of the example i'll set the default permanently to 12
var imgNum_selected = 12;
//set the initial selected option and trigger the event
$("#imgNum [value='"+imgNum_selected+"']")
.prop("selected","selected")
.change();
I'll assumed you know where to put the jQuery code
The PHP(get_images.php):
<?php
if((int) $_GET['imgs'] > 0){
$limit = (int) $_GET['imgs'];
} else {
$limit = 12;
}
$mysql_link = mysql_connect("localhost", "root", "root");
mysql_select_db("new_arrivals_imgs") or die("Could not select database");
$query = mysql_query("SELECT `imgURL`,`imgTitle` FROM `images` ".
"ORDER BY `imgDate` DESC LIMIT " . $limit * $curPage . ", $limit") or die(mysql_error());
if(!$query) {
echo "Cannot retrieve information from database.";
} else {
while($row = mysql_fetch_assoc($query)) {
echo "<li><a href='new_arrivals_img/".$row['imgURL']."' class='gallery' title='".$row['imgTitle']."'><img src='new_arrivals_img/thumbnails/".$row['imgURL']."'></a></li>";
}
}
?>
And by the way i did not test this, i hope you find something useful

Related

Select filter dropdown/pagination with only php

I'm new to this site and still fairlu new to PHP so not sure if this is were I need to place my question but here goes. I am currently trying to create a filter for my table using PHP.
The filter options are already in my database; e.g I have a species column which currently contains Snake and Lizard. I have managed to get the options to display in a Dropdown list so when selected it correctly filters either Snake or Lizard, they work and filter correctly however the main problem I have is that when I select the option to progress through the filtered pages using the numbered navigation buttons it clears my filter option and shows everything in the database again. Is it possible to make lock the selection until cleared or another item is selected?
i.e. If I select Lizard from the dropdown is it possible to keep this selection until another option is selected.
Just to clarify, I am using PHP.
`
if (!empty($_POST['dropdown']) && $_POST['dropdown'] == 'snake') {
$sql = "SELECT * FROM animal where species = 'snake' and user = '$username' LIMIT $start_from,".$limit;
$all_data=mysqli_query($con,$sql);
$user_count = mysqli_fetch_row($all_data); // say total count 9
$total_records = $user_count[0]; //9
$total_pages = ceil($total_records / $limit); // 9/3= 3
}
else if(!empty($_POST['dropdown']) && $_POST['dropdown'] == 'lizard') {
$sql = "SELECT * FROM animal where species = 'lizard' and user = '$username' LIMIT $start_from,".$limit;
$all_data=mysqli_query($con,$sql); //added
$user_count = mysqli_fetch_row($all_data); // say total count 9
$total_records = $user_count[0]; //9
$total_pages = ceil($total_records / $limit); // 9/3= 3
}
else { //added
$sql = "SELECT * FROM animal where user = '$username' LIMIT $start_from,".$limit;
$all_data=mysqli_query($con,"select count(*) from animal where user = '$username'");
$user_count = mysqli_fetch_row($all_data); // say total count 9
$total_records = $user_count[0]; //9
$total_pages = ceil($total_records / $limit); // 9/3= 3
}
$num = 0;
// if($result = mysqli_query($con, $query)){
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
while($row = mysqli_fetch_array($result)){
if ($num++ % 4== 0 && $num > 1) echo '</tr><tr>';
echo "<td>" . $row['animal'] . "</td>";
// }
// echo "</tr>";
}
// echo "</table>";
}
}
$current_page = isset($_GET['page'])?$_GET['page'] : 1;
for ($page = $start_page; $page <= $end_page; $page++){
if ($total_pages > 0) {
if ($page == $current_page) {
$active_class = "active";
echo"<button class='btn' class='active' a href='room.php?page=".($page)."'>$page</a></button>";
echo " ";
}
// else {
// else if ($num == $limit){
else if ($num == $limit){
echo ''.$page.'';
echo " ";
}
}
}
echo "<form id='form_id' method='post' name='myform'>";
echo "<select name='dropdown'>";
// echo "<option value='All'>All</option>";
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
echo "<option name='all'>" . $row['species'] . "</option>";
}
echo "</select>";
echo "<input id='submit' name='submit' type='submit' value='submit'>";
echo "</form>";
`
this is the grab from options display to a page into a table and a filter with pagination
Your question is not fully clear, but perhaps you are looking for the selected attribute.
<select name="species">
<option value="Snake">Snake</option>
<option value="Lizard" selected>Lizard</option>
</select>
with PHP you could do something like this:
<?php
$selectedSpecies = $_POST['species'];
?>
<select name="species">
<?php foreach (['Snake', 'Lizard'] as $species) { ?>
<option value="<?= $species; ?>" <?= $species === $selectedSpecies ? 'selected' : ''; ?>><?= $species; ?></option>
<?php } ?>
</select>

Dropdown of tables to show content

This script allows the user to choose a table from the dropdown and then displays the contents of the chosen table.
At the moment the DB connection is working.
A list of tables is shown in the dropdown.
Problem: No content from the database table is shown.
I have checked through the code and everything looks OK, but it still only seems to partially work.
<?php
//update this to your DB connection details.
$dbh = "localhost";
$dbn = "dbname";
$dbu = "dbuser";
$dbp = "dbpass";
$conn = mysql_connect($dbh,$dbu,$dbp) or die("Unable to connect do database.");
mysql_select_db($dbn, $conn) or die("Unable to select database.");
//Some vars for Order by and Limit.
if (!isset($ordBy)){
$ordBy = 1;
}
if (!isset($ps)){
$ps = 0;
}
if (!isset($ord)){
$ord = 1;
}
if ($ord == 1){
$tOrder = "ASC";
} else {
$tOrder = "DESC";
}
//Tables drop-down
$result = mysql_query("SHOW TABLES FROM $dbn") or die("Cannot list table names.");
echo "
<form name=\"table_browser\" action=\"".$PHP_SELF."\" method=\"GET\" >
<select name=\"t\" onChange=\"javascript:submit();\">
<option>Select a table</option>
";
while ($row = mysql_fetch_row($result)){
echo " <option value=".$row[0].">".$row[0]."</option>\n";
}
echo " </select>
</form>\n";
if (!isset($t)){
die("Please select a table");
}
//Get number of rows in $t and then select
$result = mysql_query("SELECT COUNT(*) FROM $t") or die("The requested table doesn't exist.");
$total = mysql_result($result,0);
$qry = "SELECT * FROM $t ORDER BY ".$ordBy." ".$tOrder." LIMIT ".($ps*20).",20 ";
if (isset($qry)) {
$result = mysql_query($qry) or die("The requested table doesn't exist.");
$i = 0;
while ($i < mysql_num_fields($result)) {
$meta = mysql_fetch_field($result);
if (!$meta) {
echo "No information available on the table<br />\n";
}
$name[$i] = $meta->name;
$i++;
}
//Display table details
echo "Rows ".($ps*20+1)." to ".((($ps+1)*20 < $total) ? (($ps+1)*20) : ($total))." of $total from table:
<b>$meta->table</b>\n<br /><br />\n";
//Count results
if ($ps > 0) {
echo "20 Previous - ";
} else {
echo "20 Previous - ";
}
if ((($ps+1)*20) < $total ){
echo "Next 20\n";
} else {
echo "Next 20\n";
}
//Column names
echo "<br /><br />\n<table>\n <tr>\n";
for ($j = 0; $j < $i; $j++){
echo " <td><b>$name[$j]</b>";
if ($ordBy == $name[$j]) {
echo "<img src=\"images/arrow$ord.gif\">";
}
echo "</td>\n";
}
echo " </tr>\n";
//Data
while ($row = mysql_fetch_array($result)){
echo " <tr onmouseover=\"this.style.background='#DDDDDD'\" onmouseout=\"this.style.background=''\">";
for ($j = 0; $j < $i; $j++){
echo "<td>".$row[$name[$j]]."</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
}
mysql_close();
?>
#gentlebreeze - my eyes hurt from trying to read that - but I can't see where you are actually setting the variable called $t - which is used to determine the table. You should have
$t = $_GET['t'];
somewhere before the line:
....if (!isset($t)){....
because you need to use it in the line:
....$result = mysql_query("SELECT COUNT(*) FROM $t"....
and you should not be using mysql_query either - old and now deprecated. You should switch to PDO and bound variables.

How to display certain rows from mysql with variable sent via HTML form

I'm trying to get certain data which meets the criteria from the database using AND condition with user searchable HTML form which sends the data to the search.
Code:
<?php
$conn = new mysqli('localhost', 'user', 'pass', 'db');
if ($conn->connect_error) die($conn->connect_error);
$conn->set_charset("utf8");
if (isset($_POST['Kohderyhmä']) &&
isset($_POST['Näytön aste']) &&
isset($_POST['Vaikutusten vahvuus']) &&
isset($_POST['Käyttökelpoisuus']) &&
isset($_POST['text']))
{
$Kohderyhmä = get_post($conn, 'Kohderyhmä');
$Näytön_aste = get_post($conn, 'Näytön aste');
$Vaikutusten_vahvuus = get_post($conn, 'Vaikutusten vahvuus');
$Käyttökelpoisuus = get_post($conn, 'Käyttökelpoisuus');
$text = get_post($conn, 'text');
$query = "SELECT * FROM `tietokanta`
WHERE Kohderyhmä='$Kohderyhmä' AND `Näytön aste`='$Näytön_aste' AND `Vaikutusten vahvuus`='$Vaikutusten_vahvuus' AND `Käyttökelpoisuus: luokka`='$Käyttökelpoisuus'";
}
$results = $conn->query($query);
if (!$results) die ("Database access failed: " . $conn->error);
$rows = $results->num_rows;
for ($j = 0 ; $j < $rows ; ++$j)
{
$results->data_seek($j);
$row = $results->fetch_array(MYSQLI_ASSOC);
echo '<h3>' . $row['Nimi'] . '</h3><br />';
echo '' . $row['Kokonaisarvio'] . '<br />';
echo '' . $row['Kuvaus'] . '<br /><br />';
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<b>Kohderyhmä</b><br />
<select name="Kohderyhmä" style="width: 150px;">
<option value="Kaikki">Kaikki</option>
<option value="Pikkulapset">Pikkulapset</option>
<option value="Alle kouluikäiset">Alle kouluikäiset</option>
<option value="Alakouluikäiset">Alakouluikäiset</option>
<option value="Nuoret">Nuoret</option>
<option value="Perheet">Perheet</option>
<option value="Vanhemmat">Vanhemmat</option>
<option value="Työntekijät">Työntekijät</option>
</select>
<br />
<b>Näytön aste</b>
<select name="Näytön aste" style="width: 150px;">
<option value="Kaikki">Kaikki</option>
<option value="Vahva">Vahva</option>
<option value="Kohtalainen">Kohtalainen</option>
<option value="Heikko">Heikko</option>
<option value="Ei riittävää näyttöä">Ei riittävää näyttöä</option>
<option value="Ei arvioitu">Ei arvioitu</option>
</select>
<br />
<b>Vaikutusten vahvuus</b>
<select name="Vaikutusten vahvuus" style="width: 150px;">
<option value="Kaikki">Kaikki</option>
<option value="Vahva">Vahva</option>
<option value="Kohtalainen">Kohtalainen</option>
<option value="Heikko">Heikko</option>
<option value="Ei vaikutusta">Ei vaikutusta</option>
<option value="Ei arvioitu">Ei arvioitu</option>
</select>
<br />
<b>Käyttökelpoisuus</b>
<select name="Käyttökelpoisuus" style="width: 150px;">
<option value="Kaikki">Kaikki</option>
<option value="Vahva">Vahva</option>
<option value="Kohtalainen">Kohtalainen</option>
<option value="Heikko">Heikko</option>
<option value="Ei käyttökelpoinen">Ei käyttökelpoinen</option>
<option value="Ei arvioitu">Ei arvioitu</option>
</select>
<br />
<br />
Haku: <input type="text" name="text" />
<input type="submit" value="Hae" />
</form>
I haven't used PHP to contact database before so the PHP code is very messy.
I don't understand any more than the very basics from PHP, I haven't used variables or objects or anything complex before.
HTML form:
variable1
variable2
variable3
variable4
variable5
--->
PHP script:
select * from db
where variable1 and variable2 and variable3 and variable4
--->
display results matching the criteria
Current code causes this error message in error_log:
PHP Warning: mysqli::query(): Empty query in /home/user/public_html/folder/script.php on line 23
I have already tried over 15 different variations of variables and sql query in total and nothing has worked..
If we shorten your if (isset($_POST ... something you can clearly see. This instruction
$results = $conn->query($query);
is always executed, regardless of whether isset returns true or not.
if (isset($_POST['Kohderyhmä']) &&
...)
{
$Kohderyhmä = get_post($conn, 'Kohderyhmä');
...
$query = "SELECT * FROM `tietokanta`...."
}
$results = $conn->query($query);
So if only one field has not been filled out correctly, the error is always the same :
PHP Warning: mysqli::query(): Empty query in ....
This makes it difficult to determine where the fault really comes from.
Place the curly bracket } behind database logic.
if (isset($_POST['Kohderyhmä']) &&
...)
{
$Kohderyhmä = get_post($conn, 'Kohderyhmä');
...
$query = "SELECT * FROM `tietokanta`...."
$results = $conn->query($query);
if (!$results) die ("Database access failed: " . $conn->error);
$rows = $results->num_rows;
for ($j = 0 ; $j < $rows ; ++$j)
{
$results->data_seek($j);
$row = $results->fetch_array(MYSQLI_ASSOC);
....
}
}
?>
create a short test program to test only the database. Set only really necessary data fields in the query
test.php
<?php
$conn = new mysqli('localhost', 'user', 'pass', 'db');
if ($conn->connect_error) die($conn->connect_error);
$conn->set_charset("utf8");
$Kohderyhmä = "KohderyTest"; // replace with really existing values
$query = "SELECT * FROM `tietokanta` WHERE Kohderyhmä='".$Kohderyhmä."' ";
$results = $conn->query($query);
if (!$results) die ("Database access failed: " . $conn->error);
while ($row = $results->fetch_assoc()) {
echo "<h3>" . $row['Nimi'] . "</h3><br />";
echo $row['Kohderyhmä'] ."<br /><br />";
}
$results->free();
?>
Add hardcoded variables $Näytön_aste = "reallyExistingValue"; , add query data field for data field and watch when it starts to stutter.
Also we can not see your function get_post()
If you mean the Wordpress function get_post(), your call to the function is wrong.
I can well imagine that the failure from the function get_post() comes.
And you always false or empty values assigns.
$Kohderyhmä = get_post($conn, 'Kohderyhmä');
assign it direct.
$post = $_POST;
if (isset($post['Kohderyhmä']) &&
...)
{
$Kohderyhmä = $post['Kohderyhmä'];
...
Also you are using all select fields from the <form>, in the query.
4 Select's with 8,6,6,6 options means
8x6x6x6 == 1728
1728 possibilities are you shure you have one datarecord where all values matches.
WHERE Ko...='$Ko...' AND `Näy...`='$Näy...' AND `Vai...`='$Vai...' AND `Käy...`='$Käy...'";
WHERE All four Datafields must match to get a result !!!!!!!!!!!!!
You have to find a combination where all four values simultaneously exist.
UPDATE
OP new question :
If you want empty or some named values stop searching for a value in
database.
required every single variable to be found in the database which it
didn't find because I couldn't set the variable and there is no value
for "Kaikki" in the database, the word "Kaikki" means all choices
below that choice in the HTML form and for that I need some PHP
Here comes the new test.php
1) don't do $post['Näytön aste']; In the form the name is
<select name="Näytön aste" style="...">.
This will translated by submit to
$post['Näytön_aste']; look at the underscore _
This must be done with all select name with spaces in the name !!
2) That was the reason why you get not all $_POST[....] values !
OK ?
3) replace in your form
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
with
<form action="testNew.php" method="POST">
testNew.php
<?php
$conn = new mysqli('localhost', 'user', 'pass', 'db');
if ($conn->connect_error) die($conn->connect_error);
$conn->set_charset("utf8");
$post = $_POST;
if (isset($post['Kohderyhmä']) &&
isset($post['Näytön_aste']) &&
isset($post['Vaikutusten_vahvuus']) &&
isset($post['Käyttökelpoisuus']))
{
$Kohderyhmä = $post['Kohderyhmä'];
$Näytön_aste = $post['Näytön_aste'];
$Vaikutusten_vahvuus = $post['Vaikutusten_vahvuus'];
$Käyttökelpoisuus = $post['Käyttökelpoisuus'];
} else { die ("No valid values"); }
$count = 0;
$and = "";
$query = "";
if (!empty($Kohderyhmä) && $Kohderyhmä !="Kaikki" ) {
if ($count > 0) { $and = " AND "; }
$count++;
$query = $query.$and."`Kohderyhmä`= '".$Kohderyhmä."'";
}
if (!empty($Näytön_aste) && $Näytön_aste !="Kaikki" ) {
if ($count > 0) { $and = " AND "; }
$count++;
$query = $query.$and."`Näytön aste`= '".$Näytön_aste."'";
}
if (!empty($Vaikutusten_vahvuus) && $Vaikutusten_vahvuus !="Kaikki" ) {
if ($count > 0) { $and = " AND "; }
$count++;
$query = $query.$and."`Vaikutusten vahvuus`= '".$Vaikutusten_vahvuus."'";
}
if (!empty($Käyttökelpoisuus) && $Käyttökelpoisuus !="Kaikki" ) {
if ($count > 0) { $and = " AND "; }
$count++;
$query = $query.$and."`Käyttökelpoisuus: luokka`= '".$Käyttökelpoisuus."'";
}
if ($count > 0) {
$query = "SELECT * FROM `tietokanta` WHERE ".$query;
} else {
$query = "SELECT * FROM `tietokanta`";
}
echo $query;
if ($results = $conn->query($query)) {
while ($row = $results->fetch_assoc()) {
echo "<h3>" . $row['Nimi'] . "</h3><br />";
echo $row['Kohderyhmä'] ."<br /><br />";
}
} else {
echo "with your choices no records were found";
}
$results->free();
?>
$query = "SELECT * FROM `tietokanta`
WHERE Kohderyhmä='{$Kohderyhmä}' AND `Näytön aste`='{$Näytön_aste}' AND `Vaikutusten vahvuus`='{$Vaikutusten_vahvuus}' AND `Käyttökelpoisuus: luokka`='{$Käyttökelpoisuus}'";
Replace your query with this, and try.

how to access values in jquery muiltiselect through php

I'm using jquery multiselect and in options i'm fetching data from database these are basically available seats in a buss.. when user selected some seats and press the button i'm putting values on $_POST and using update query updating selected seats as reserved please help here is the code
** HTML SELECT tag with jquery and php for fetching data this is working fine **
<form action="" method="post">
<label for="required">Required</label>
<select id="required" multiple="multiple" data-placeholder="Select attendees..." name="required">
<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
$link = mysql_select_db("bus") or die(mysql_error());
$query = " select seats.seatNo from seats where seats.isactive = 0 and seats.busID = 1";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$seatNo = $row['seatNo'];
?>
<option> <?php echo $seatNo ?> </option>
<?php } ?>
</select>
And then I'm getting selected seats here and updating the db
<?php
$con;
$link;
if(isset($_POST['submit']))
{
for($i = 0; $i<5; $i++)
{
$selected = $_POST['required'];
}
$insert = " update seats set seats.isactive = 1 where seats.seatNo = $selected and seats.busID = 1";
$q = mysql_query($insert) or die(mysql_error());
if($q)
{
echo " record updated ";
}
else
{
echo " couldn't update ";
}
}
?>

Chained dropdown option not pulling previous values through in to query

I have found a example of chained dropdown boxes, however i am struggling to ensure that the 3rd box uses both the previous boxes in showing the required results.
The boxes are intended to show the following,
DROP DOWN BOX 1 = Select a sector
DROP DOWN BOX 2 = Select a Level
DROP DOWN BOX 3 = Select a Qualification
On the last SQL query i have shown a $HELP, i think this is where im having my problems, i think it is loosing the previously stored value in dropdown box 1 when dropdown box 2 is selected.
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT SSA1Text FROM qualifications ORDER BY SSA1Text ASC")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['SSA1Text'].'">'.$tier['SSA1Text'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT Level FROM qualifications WHERE SSA1Text='$drop_var' ORDER BY Level ASC")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['Level'].'">'.$drop_2['Level'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
{//**************************************
// Second selection results //
//**************************************
if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var)
{
include_once('db.php');
$result = mysql_query("SELECT * FROM qualifications WHERE Level='$drop_var' AND SSA1Text='$HELP'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['Title'].'">'.$drop_3['Title'].'</option>';
}
echo '</select> ';
echo '<input type="submit" name="submit" value="Submit" />';
}
?>
Any help would be much appreciated.
You could pass both select variables to drop_2 function?
function drop_2($drop_var1, $drop_var2 == null) {
if ($drop_var2 !== null) {
$sqlSnipet = " AND SSA1Text='$drop_var2'"
}
$result =
mysql_query(
"SELECT *
FROM qualifications
WHERE Level='$drop_var' " .
$sqlSnipet
) or die(mysql_error());
}

Categories