It's hard to implement a search method in a jTable.
Codes:
generaterecords.php:
<?php
$page_title = "Generate Reports";
require_once('template/header.php');
require_once('template/navmenu.php');
require_once('template/content-top.php');
?>
<div class="filtering">
<form>
<select name="year" >
<option value="0000">Year</option>
<?php
for($i=date('Y'); $i>2012; $i--) {
echo '<option value="'.$i.'"'.'>'.$i.'</option>'."\n";
}
?>
</select>
<select name="month">
<option value="0">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<button type="submit" id="LoadRecordsButton">Load records</button>
</form>
<div id="PeopleTableContainer" style="width: 850px;"></div>
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Payment Records',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'payment.paymentdate ASC',
actions: {
listAction: 'payment.php?action=list'
},
fields: {
paymentid: {
key: true,
create: false,
edit: false,
list: false
},
lname: {
title: 'Last Name',
width: '20%',
create: false,
edit: false
},
fname: {
title: 'First Name',
width: '20%',
create: false,
edit: false
},
mname: {
title: 'Middle Name',
width: '20%',
create: false,
edit: false
},
paymenttype: {
title: 'Type',
width: '20%',
create: false,
edit: false
},
paymentdate: {
title: 'Date',
width: '20%',
create: false,
edit: false
},
totalrate: {
title: 'Total Rate',
width: '20%',
create: false,
edit: false
},
paymentamt: {
title: 'Amount',
width: '20%',
create: false
},
balance: {
title: 'Balance',
width: '20%',
create: false,
edit: false
}
}
});
//Load person list from server
//$('#PeopleTableContainer').jtable('load');
//Re-load records when user click 'load records' button.
// Backup
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#PeopleTableContainer').jtable('load', {
year: $('#year').val(),
month: $('#month').val()
});
});
//Load all records when page is first shown
// $('#LoadRecordsButton').click();
});
</script>
<br>
<br>
<?php
// footer
require_once('template/footer.php');
?>
payment.php:
<?php
include_once ('database_connection.php');
try
{
$con = mysql_connect("localhost","kureido","tnx4standinstillwanker");
mysql_select_db("kureido", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$offresult = mysql_query("SELECT COUNT(*) AS OLRecordCount FROM official;");
$offrow = mysql_fetch_array($offresult);
$allresult = mysql_query("SELECT COUNT(*) AS AllRecordCount FROM lodger;");
$allrow = mysql_fetch_array($allresult);
$resresult = mysql_query("SELECT COUNT(*) AS ResRecordCount FROM reservation;");
$resrow = mysql_fetch_array($resresult);
$recordCount = $allrow['AllRecordCount'] - $offrow['OLRecordCount'] - $resrow['ResRecordCount'];
$year = "";
$month = "";
if (empty($_POST['year']) && empty($_POST['month']))
$year = $month = "";
else
{
$year = $_POST['year'];
$month = $_POST['month'];
}
//Get records from database
$result = mysql_query("SELECT payment.paymentid, lodger.ssn, lodger.lname, lodger.fname, lodger.mname, payment.paymenttype, payment.paymentdate, payment.totalrate, payment.paymentamt, payment.totalrate - payment.paymentamt AS balance FROM payment, lodger WHERE lodger.ssn = payment.lodger_ssn AND YEAR(paymentdate) = '" . $_POST["year"] . "' AND MONTH(paymentdate) = '" . $_POST["month"] . "' ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] .";");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
/* else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO people(Name, Age, RecordDate) VALUES('" . $_POST["Name"] . "', " . $_POST["Age"] . ",now());");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
} */
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE official SET room_code = '" . $_POST["room_code"] . "', appliancerate = '" . $_POST["appliancerate"] . "', monthlybal = '" . $_POST["monthlybal"] . "' WHERE lodger_ssn = " . $_POST["ssn"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM official WHERE lodger_ssn = " . $_POST["ssn"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
else if($_GET["action"] == "view")
{
}
//Close database connection
mysql_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>
Sometimes the server returns errors. Any ideas on how to get this fixed? generaterecords.php is the client side while payment.php is the server side.
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#PeopleTableContainer').jtable('load', {
year: $('#year').val(),
month: $('#month').val()
});
});
//remove your comments .. the code below is for running the function above when loadrecords button is clicked
$('#LoadRecordsButton').click();
Related
I'm very new to AJAX and PHP. I'm trying to implement a "like" feature on a website where users can post memes. The user should be able to click a heart-shaped image to "like" next to a meme and the "likes" value for that particular meme should increase by one in the MySQL database, however, it is not doing anything.
The MySQL table is called meme_information and it has 5 columns, "name", "email", "likes", "image_path", and "id" which is the primary key and auto increments.
Below is the code for the page where all the memes are displayed. There is some html above that I left out, but it is just the navbar and sourcing in files. I am pretty sure that the "data" value in the AJAX is wrong, but I'm not sure what I'm supposed to put in there.
browse.php
<?php
include("connecttodb.php");
$files = glob("uploads/*.*");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
$supported_file = array(
'gif',
'jpg',
'jpeg',
'png'
);
$image = $files[$i];
$path = substr($image,8);
$q = "SELECT name, email, id FROM meme_information WHERE image_path= \"$path\"";
$id = 0;
$result = $link->query($q);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Name: ". $row["name"] ."<br>";
echo "Email: ". $row["email"] ."<br>";
echo "Id: ". $row["id"] . "<br>";
$id = $row["id"];
}
}
echo '<img src="'.$image.'" style="width:400px;height:400px;"></img>';
echo '<img onclick="myFunction()" src="heart-unclicked.png" style="width:50px;height:50px;">like</img>';
echo
'<script>
function myFunction() {
$.ajax({
type: "POST",
url: "update_likes.php",
data: {"increment_by": 1},
success: function() {
alert("works");
},
error: function() {
alert("doesnt work");
},
});
}
</script>';
}
?>
I believe the part after WHERE in the SQL query is wrong. Not sure how I can get the id number from the meme that was "liked."
update_likes.php
<?php
require('connecttodb.php');
$q2 = "UPDATE meme_information SET likes = likes + 1 WHERE id='".$id."'";
echo "The id is $id" . "<br>";
$result = mysqli_query($link, $q2);
echo "<br> this is the id" . "$result";
?>
connecttodb.php
<?php
global $link;
include("dbconnect.php");
$link = new mysqli($server,$user,$password,$dbname);
if ($link->connect_errno) {
die("Connection failed: " . $link->connect_error);
} else {
print"Connection successful.";
}
?>
This might solve the issue.
<?php
include("connecttodb.php");
$files = glob("uploads/*.*");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
$supported_file = array(
'gif',
'jpg',
'jpeg',
'png'
);
$image = $files[$i];
$path = substr($image,8);
echo '<img src="'.$image.'" style="width:400px;height:400px;"></img>';
$q = "SELECT name, email, id FROM meme_information WHERE image_path= \"$path\"";
$id = 0;
$result = $link->query($q);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Name: ". $row["name"] ."<br>";
echo "Email: ". $row["email"] ."<br>";
echo "Id: ". $row["id"] . "<br>";
$id = $row["id"];
echo '<img onclick="myFunction('.$id.')" src="heart-unclicked.png" style="width:50px;height:50px;">like</img>';
}
}
echo
'<script>
function myFunction(id) {
$.ajax({
type: "POST",
url: "update_likes.php",
data: {"increment_by": 1,"id": id},
success: function() {
alert("works");
},
error: function() {
alert("doesnt work");
},
});
}
</script>';
}
?>
update_likes.php
<?php
require('connecttodb.php');
if(isset($_POST['id']))
{
$q2 = "UPDATE meme_information SET likes = likes + 1 WHERE id='".$_POST['id']."'";
echo "The id is $id" . "<br>";
$result = mysqli_query($link, $q2);
echo "<br> this is the id" . "$result";
}
?>
how to fill dropdown values on selection of multiple dropdown.for example i have following Dropdown list.
On select of second dropdown i wants to fill Third Dropdown With Single selection How can i do. ?
My current code for this is as follow.
//CALL FOR SECOND DROPDOWN
$(document).ready(function(){
$('#select4').on('change',function(){
var subcatgoryId = $(this).val();
console.log(subcatgoryId);
if(subcatgoryId){
$.ajax({
type:'POST',
url:'ajax_load_specification.php',
data:{subcatgoryId: subcatgoryId},
success:function(html){
alert(html);
//$('#select5').html(html);
//$('#loading1').css("display","none")
},
error: function (jqXHR, exception) {
alert("Got Some Errore");
}
});
}else{
$('#select5').html('<option value="">Select Category first</option>');
}
});
});
and php code is as follow
if(isset($_POST["subcatgoryId"]) )
{
$subcategory = explode(',', $_POST["subcatgoryId"]);
print_r($_POST["subcatgoryId"]);
foreach ($subcategory as $key => $value)
{
echo $key;
echo "<br>";
$query1 = "SELECT * FROM m_subcategory WHERE id = ".$item." ";
$query1 = $conn->query($query1);
$query1 = $query1->fetch_object();
if($query1){
$id = $query1->id;
$name = $query1->name;
echo '<option value="'.$id.'">'.$name.'</option>';
}else{
echo '<option value="">We Get Empty Category</option>';
}
}
}
Just Use For Loop And it starts working
if(isset($_POST["subcatgoryId"]) )
{
$subcategory = $_POST["subcatgoryId"];
$len=count($subcategory);
for ($i=0; $i < $len; $i++) {
$query1 = "SELECT * FROM m_subcategory WHERE id = ".$subcategory[$i]." ";
$query1 = $conn->query($query1);
$query1 = $query1->fetch_object();
if($query1){
$id = $query1->id;
$name = $query1->name;
echo '<option value="'.$id.'">'.$name.'</option>';
}else{
echo '<option value="">We Get Empty Category</option>';
}
}
}
Someone who knows about JTable? I´ve tried to create a specfici table with this plugin however I can´t find the right way. I donwloaded the examples and modify it for my needs. But after change the code I have a blank page only in the browser.
Can someone explain to me where is/are the mistake/s?
index.php
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 50,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?action=list',
createAction: 'PersonActionsPagedSorted.php?action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false,
width: '5%',
},
Fecha: {
title: 'Fecha',
width: '10%',
type: 'date',
}
Nombre: {
title: 'Nombre',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3','4': 'Option4' }
},
Turno: {
title: 'Turno',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Info: {
title: 'Info',
width: '45%',
type: 'textarea'
},
Estado: {
title: 'Estado',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Criticidad: {
title: 'Criticidad',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
});
</script>
PersonActionsPagedSorted.php
<?php
try
{
//Open database connection
$con = mysql_connect("localhost","root","");
mysql_select_db("jtabletestdb", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM people;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM people ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO people(Fecha, Nombre, Turno, Info, Estado, Criticidad) VALUES('" . $_POST["Fecha"] . "', '" . $_POST["Nombre"] . "','" . $_POST["Turno"] . "', '" . $_POST["Info"] . "','" . $_POST["Estado"] . "', '" . $_POST["Criticidad"] . ";");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE people SET Fecha = '" . $_POST["Fecha"] . "', Nombre = '" . $_POST["Nombre"] . "', Turno = '" . $_POST["Turno"] . "', Info = '" . $_POST["Info"] . "',Estado ='" . $_POST["Estado"] . "', Criticidad = '" . $_POST["Criticidad"]. "' WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM people WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Close database connection
mysql_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>
If you wonder, yeah I´m very novice in this world and I suppose the answer is simple.
iam using JQuery jTable and PHP for my Website.
While Loading Data from Database work perfectly! but when Update the Data: send POST to
edit the rows doesent update MySQL database, just jtable, but after reload the Page "load from mysql" the data is back to befor update.
Delete data work, only update don`t update
my js:
//Prepare jTable
$('#log').jtable({
title: 'Domains',
toolbar: {
hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
hoverAnimationDuration: 60, //Duration of the hover animation.
hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
items: [] //Array of your custom toolbar items.
},
paging: true,
sorting: true,
pageSize : 10,
pageSizes : [ 2, 5, 10, 15, 20, 50, 75, 100, 200, 500 ],
defaultSorting: 'domain ASC',
actions: {
listAction: 'actions.php?action=list',
createAction: 'actions.php?action=create',
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
},
messages: DeutschMessages,
fields: {
id_domain: {
key: true,
title: 'ID',
create: false,
edit: false,
list: true
},
domain: {
title: 'Domainname',
width: '30%'
},
exclude: {
title: 'Exclude',
defaultValue: 'www,ns,ftp,mail,mx,pop,smtp',
width: '40%'
},
dnsip: {
title: 'DNS Server',
width: '20%'
},
key: {
title: 'Key',
sorting: false,
list: false,
width: '20%'
},
enable_a: {
title: 'A',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_ns: {
title: 'NS',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_url: {
title: 'URL',
options: ['1','0'],
sorting: false,
width: '20%'
},
max: {
title: 'MAX',
defaultValue: '-1',
sorting: false,
width: '20%'
}
}
});
//Load person list from server
$('#log').jtable('load');
});
and the php script:
//Open database connection
$con = mysql_connect($mysql_host,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db,$con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
if (empty($_POST['search']))
{
$search = NULL;
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
$result = mysql_query("SELECT * FROM domains ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
}
else
{
$search = mysql_real_escape_string($_POST['search']);
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%';");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
$_SESSION["query"] = "SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"];
$_SESSION["contador"] = "SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%'";
}
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows;
$jTableResult['TotalRecordCount'] = $recordCount;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO `domains`(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`) VALUES ('', '".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM domains WHERE id_domain = last_insert_id();"); // WHERE id_domain = last_insert_id();"); // id_domain = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
$id = $_REQUEST['id_domain'];
//Update record in database
$result = mysql_query("UPDATE domains SET domain = '" . addslashes($_POST["domain"]) . "', exclude = '" . addslashes($_POST["exclude"]) . "', dnsip = '" . addslashes($_POST["dnsip"]) . "', key = '" . addslashes($_POST["key"]) . "', enable_a = '" . addslashes($_POST["enable_a"]) . "', enable_ns = '" . addslashes($_POST["enable_ns"]) . "', enable_url = '" . addslashes($_POST["enable_url"]) . "', max = '" . addslashes($_POST["max"]) . "' WHERE id_domain = $id;");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
else if($_GET["action"] == "listname")
...
after hit Update:
Response is always "ok"
i can´t catch the error ./
any help ?
Have you seen this?
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
should be:
updateAction: 'actions.php?action=update'
// deleteAction: 'actions.php?action=delete'
without the comma at the end of the first line (you removed the following row so this is the last one.
Furthermore: you should consider to switch to PDO for mysql safe site.
Last but not least: you are not handling errors in the insert query. Try something like:
if(mysql_query("INSERT INTO `domains`
(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`)
VALUES
('','".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');")){ $jTableResult['Result'] = "OK";
}else{
$jTableResult['Result'] = "KO";
}
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());
}