I'm doing a program that would ask user to search from Mysql table based on onKeyup. But it seems that the response time is very slow while I don't have that much of data ~ 2873 records.
Here is my PHP code :
<?php
session_start();
if(isset($_SESSION['master'])){
require_once('connect_db.php');
require_once('output_fns.php');
<div id="openModal6" class="modalDialog6">
<div>
X
<h2><center>Search Item</center></h2>
<p>
<table>
<tr><td>
<b>Item No. :</b><br />
//User input and onKeyup
<input type="text" value="" id="item_s" autofocus required onKeyUp="related_item(document.getElementById('item_s').value,document.getElementById('store_s').value);">
<td><b>Stor</b><br />
//User select Store by default usually its first store
<select name='store_s' id='store_s'>
<?php
$query = "SELECT * from stores_list";
$result = mysql_query($query);
if(mysql_num_rows($result)>0){
$num = mysql_num_rows($result);
for($i=0;$i<$num;$i++){
$row = mysql_fetch_assoc($result);
echo "<option value='{$row['short']}'>{$row['short']}</option>";
}
echo "</select>";
}
else{
//No Stores Available
echo "No Stores Found !";
}
?>
</td>
</tr>
<tr><td align="center" colspan="3">
//Response Output Here
<div id="txtHint4">Waiting...</div>
</td></tr>
</table>
</p>
</div>
</div>
<?php
}
Of course this is a Modal dialogue so it basically opens up when user Click on |Search Button| and using Onclick=
As for Ajax get_item.php
<?php
require_once('connect_db.php');
$q=$_GET['q'];
$s=$_GET['s'];
if($_GET['q']=="---"){
return true;
exit();
}
//Select Result From table where item Like
$query="SELECT * FROM store_items WHERE item_no LIKE '".$q."%' AND store = '".$s."' ORDER by sub Asc";
$result = mysql_query($query);
if(mysql_num_rows($result)>0){
echo "<br />";
echo "<table width=100% height=% align=center border=1 bgcolor=white cellpadding=5 cellspacing=0 style='font-size:12px;'>";
echo "<tr><td align=center><b>Item Number</b><td align=center><b>QTY</b><td align=center><b>Unit Cost</b></td><td align=center><b>Unit Sell</b></td><td align=center><b>Cat</b></td><td align=center><b>Sub</b></td><td align=center><b>Description</b></td><td align=center><b>Store</b></td></tr>";
while($row = mysql_fetch_assoc($result)){
echo "<tr><td align=center>{$row['item_no']}</td><td align=center>{$row['qty']}<td align=center>{$row['actual_price']}</td><td align=center>{$row['selling_price']}</b></td><td align=center>{$row['cat']}</td><td align=center>{$row['sub']}</td><td align=center>{$row['short']}</td><td align=center>{$row['store']}</td></tr>";
//End of While loop
}
}
else{
echo "<br /><center><font color=red>Sorry Item Number Not Found !</font></center>";
}
?>
And finally the Function related_item
function related_item(str,str2)
{
if (str=="")
{
document.getElementById("txtHint4").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint4").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_item.php?q="+str+"&s="+str2,true);
xmlhttp.send();
}
What have I done wrong this far? it should fetch data quickly from the table, I don't understand like around 4-5 seconds waiting time to see data coming up inside <div id='txtHint4'>Response</div>
Please Note the items are only numbers , example (001200201000)
UPDATE :
I've checked chrome developer tool network to test out the delay part and it seems the delay goes on get_item.php file Here are the results
Query 0.36
Stalled 0.5
Request Sent 0.14ms
Waiting (TTFB) 77.555ms
Content Download 3.40s
So does it mean that there is something wrong with my PHP file? what other or better way to enhance the code? Its straight forward reading from table. Maybe I'm missing something here
Related
I am working on a project at the moment. In iI am using ajax to update and calculate scores, which works fine. However, I have a color scheme that changes according to the score. The color does change, but only after the page is refreshed. Is there anyway I can get the color to change with refreshing the page?
Here is the code that I am using to assign colors:
<?php $row_class = "";
while($row = mysql_fetch_assoc($dbResult1))
{
if($row['total_mai'] <= 2)
$row_class = "success";
else if($row['total_mai'] >= 5)
$row_class = "danger";
else if($row['total_mai'] >= 3 and $row['total_mai'] < 5)
$row_class = "warning";
// echo $row_class;
?>
In another page, here is an example of one question, it has three answers and depending on the answer a color is assigned based on the score
<tr>
<td class="form-group col-md-6">Is the duration of therapy acceptable?</td>
<td class="form-group col-md-6">
<p class="radio-inline">
<input type="radio" name="therapydur" id="j1" value="0" <?php echo $j1; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
A
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j2" value="0" <?php echo $j2; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
B
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j3" value="1" <?php echo $j3; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','1','<?php echo $row['p_id']; ?>')">
C
</input></p>
</td>
</tr>
Here is the ajax from the same page:
<script language="javascript" type="text/javascript">
function ajaxFunction(title,id,val,p_id)
{
//alert("test");
//alert(id);
//alert(val);
//alert(title);
//alert(p_id);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
var resp = xmlhttp.responseText;
var split_v = resp.split("__");
//alert(split_v.length);
//alert(split_v[1]);
document.getElementById("ajaxDiv_"+id).innerHTML=split_v[0];
document.getElementById("ajaxTotal").innerHTML=split_v[1];
}
}
xmlhttp.open("GET","ajax_mai.php?pdr_id="+id+"&value="+val+"&title="+title+"&p_id="+p_id,true);
xmlhttp.send();
return true;
}
</script>
I am very new to php and I am trying to show some specific records based on a input (from drop down).
From Customer.php page I am selecting a customer which will send a request to analysis.php which will perform DB operations and displays results in a tabular format. Now I am trying to draw a graph using the results from DB.
I donno where to start, any help would be much appreciated.
Below is my code.
customer.php
<html>
<head>
<title>Customer</title>
<script type="text/javascript">
function validateBox(){
var customer_name = document.getElementById('customer_name').value;
if(customer_name.length == 0){
alert("Please select customer name");
return false;
//handle validation response here
} else {
//document.getElementById("form").submit();//submit form, or whatever the button is supposed to do...
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","analysis.php?q="+customer_name,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form class="form" id="form" method="post">
<table align="center">
<tr>
<td>
<label>Customer Name :</label></td>
<td><select name="customer_name" id="customer_name" required>
<option value="">Select</option>
<option value="Dell">Dell</option>
<option value="HP">HP</option>
<option value="Lenovo">Lenovo</option>
<option value="Compaq">Compaq</option>
</select></td></tr>
<td><input onclick="validateBox()" type="button" name="addrecord" value="Begin Analysis"></td></table>
</form>
</body>
</html>
and analysis.php looks like
<?php
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("db", $connection);
$q = $_GET['q'];
$resource=array();
$z=0;
$SQL = mysql_query("select resources from users ", $connection);
while ($db_field = mysql_fetch_assoc($SQL)) {
$a = $db_field['resources'];
$resource[$z] = $a;
$z++;
}
$resourcelength = count($resource);
?>
<table border = "2" width = "30%" align='center'>
<tr align ="center">
<th >resource</th>
<th ># Count</th>
<?php
for($x = 0; $x < $resourcelength; $x++) {
print("<tr>");
print("<td align = 'center'>$resource[$x]</td>");
$y=$resource[$x];
$SQL = mysql_query("SELECT count(distinct(ticket_id)) as total FROM tickets WHERE resource_name='".$y."' ", $connection);
while ($db_field = mysql_fetch_assoc($SQL)) {
$a = $db_field['total'];
print("<td align = 'center'>$a</td>");
}
print("</tr>");
}
?>
</table>
and the output will be like
Resource Total
A 30
B 12
C 15
D 0
X 13
I want to convert this to a graph, I tried to include google charts, but no luck.
Thanks in advance. :)
I would suggest you to use pChart. It's a free PHP library, really easy to use and it contains a lot of basic examples.
Im getting a set of values from the database to show in a drop down list. Once the user selected an item from the drop down list the selected item should be assigned to a SESSION variable. I tried this but yet it is not working. Please smeone help me to sort it out.
<select id="FormNameSelecting" style="position:absolute; width:300px; top:50px; left:200px; "><option></option>
<?php
$result = mysqli_query($con,"SELECT * FROM Form");
while($row = mysqli_fetch_array($result)){
echo "<option value='$row[Form_ID]'>$row[Form_Name]</option>";
echo
}
?>
</select>
So I need to store these values receive from $row[Form_ID] and $row[Form_Name] in 2 session variables named $_SESSION['Form_ID'] and $_SESSION['Form_Name']; Could someone explain me how I can assign the selected item's values to these two session variables.
The selected option element must have selected attribute.
You should try something like this:
<select id="FormNameSelecting" style="position:absolute; width:300px; top:50px; left:200px; ">
<?php
$result = mysqli_query($con,"SELECT * FROM Form");
while($row = mysqli_fetch_array($result))
{
echo "<option value='{$row['Form_ID']}'";
if($row['Form_ID'] == $_SESSION['Form_ID'])
echo " selected";
echo ">{$row['Form_Name']}</option>";
}
?>
</select>
UPDATE:
You can store it in $_SESSION after the form submit
<?php
session_start(); // dont forget it!
if(isset($_POST['submit']))
{
$_SESSION['Form_ID'] = $_POST['Form_ID'];
$_SESSION['Form_Name'] = $_POST['Form_Name'];
}
?>
Try This:
In your page add this and create one more page "showValues.php"(This is the page where you want to create and use your session variable).Code of showValues.php is also given below for example.
<html>
<head>
<script>
function showValue(vals)
{
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var val= xmlhttp.responseText;
document.getElementById("tbl").innerHTML+=val;
}
}
xmlhttp.open("GET","showValues.php?vals="+vals,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table id="tbl">
<tr>
<td>
<select id="FormNameSelecting" style="position:absolute; width:300px; top:50px; left:200px; "><option></option>
<?php
$result = mysqli_query($con,"SELECT * FROM Form");
while($row = mysqli_fetch_array($result)){
echo "<option value='$row[Form_ID]'>$row[Form_Name]</option>";
echo
}
?>
</select>
</td>
</tr>
</table>
</body>
</html>
showValues.php
<?php
session_start();
$vals=$_REQUEST['vals'];
$_SESSION['SelectValue']=$vals;
echo $_SESSION['SelectValue'];
?>
try this
<form name="my_name" method="POST" action="">
<select name="FormNameSelecting" id="FormNameSelecting" style="position:absolute; width:300px; top:50px; left:200px; "> //don't forget put name at select
<option></option>
<?php
$result = mysqli_query($con,"SELECT * FROM Form");
while($row = mysqli_fetch_assoc($result)){ //prefer using assoc that array
echo "<option value='" . $row['Form_ID'] . ":::" . $row['Form_Name'] . "'>" . $row['Form_Name'] . "</option>";
}
?>
</select>
<input type="submit" name="go" value="go"/>
</form>
<?php
if(isset($_POST['go'])){
$store_sesi = explode(":::",$_POST['FormNameSelecting']);
$_SESSION['ID'] = $store[0];
$_SESSION['Name'] = $store[1];
}
?>
hope this code help you
I found one of basic php live search using ajax from youtube.com please see the sample at
http://www.youtube.com/watch?v=3fS4Ys_ZEKw that video speaking different language but i manager to type all of codes exactly of what you see from youtube.com , but different is the database name and table name, however, when I run is not showing anything to bring from mysql database even if pressed any key still not showing anything and not even errors. Can you see if i missed anything on this code compare to what you see from youtube!
search.php
<body>
<form name"form1" action="" method="post">
Enter name<input type="text" name="t1" onKeyUp="aa();"/><br />
<div id="dl"></div>
</form>
<script type="text/javascript">
function aa()
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","sea.php?nm="+document.forml.t1.value,false);
xmlhttp.send(null);
document.getElementById("dl").innerHTML=xmlhttp.responseText;
}
</script>
</body>
</html>
sea.php
<?php
$nm=$_GET("nm");
$mysqli = new mysqli("localhost", "root", "password", "table");
// Check connection
if (mysqli_connect_errno($mysqli))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($result = $mysqli->query("select * FROM product WHERE product_name like('$nm%')"))
echo"<table>";
{
echo "<tr>";
echo "<td>";?><img src="../<?php echo $row["screenshot"];?>" height="100" width="100" <?php echo "</td>" ;
echo "<td>"; echo $row["product_name"]; echo "</td>";
echo "<tr>";
}
echo "</table>";
?>
you need to get the response on onreadystatechange, do:
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) { //4:: request finished and response is ready
document.getElementById("dl").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","sea.php?nm="+document.forml.t1.value);
xmlhttp.send(null);
It's all in the question really :)
It's clearer when I put it in bullet points what I want to do, so here it goes:
I have two forms on a page, a search form, and an 'edit profile' form. Both are in working order, individually.
The edit profile form paginates through the rows of my MySQL tbl, allowing my to edit the values for each column. Currently set up to include all rows (i.e. all stored profiles).
the search form takes any of 17 different search variables and searches that same table to find a profile, or a group of profiles.
I want to be able to enter a search term (e.g. Name: 'Bob'), query the tbl as I am doing, but use AJAX to return the unique ID's of the results as an an array stored within a variable. I then want to be able to asynchronously feed that variable to my edit profile form query (the search form would have a submit button...) so I can now page through all the rows in my table (e.g. where the Name includes 'Bob'), and only those rows.
Is the above possible with the languages in question? Can anyone help me piece them together?
I'm at an intermediate-ish stage with PHP and MySQL, but am an absolute novice with AJAX. I've only ever used it to display a text string in a defined area - as seen in demos everywhere :) Therefore, treating me like a five-year-old is greatly appreciated!
Here are my current search query, and the edit-profile form, if they help at all:
The Edit Profile form:
//pagination base
if (isset($_GET['page'])) { $page = $_GET['page']; }
else { $page = 1; }
$max_results = 1;
$from = (($page * $max_results) - $max_results);
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM profiles"),0);
$total_pages = ceil($total_results / $max_results);
echo '<span id="pagination">' . 'Record ' . $page . ' of ' . $total_results . ' Records Returned. ';
if($total_results > $max_results)
{
if($page > 1)
{ $prev = ($page - 1);
echo "<input type='submit' value='<<' />";
}
if($page == 1)
{ echo "<input type='submit' value='<<' />"; }
if($page < $total_pages)
{ $next = ($page + 1);
echo "<input type='submit' value='>>' />";
}
if($page == $total_pages)
{ echo "<input type='submit' value='>>' />";
}
}
echo '</span></p>';
?>
// the query, currently selecting all but which I would have include a WHERE clause (WHERE ProfileID = $profileid...)
<?php
$sql = ("SELECT * FROM profiles
ORDER BY ProfileID
LIMIT $from, $max_results");
$rs = mysql_query($sql);
while($row = mysql_fetch_array($rs))
{
$profile = $row['ProfileID'];
?>
<form id="profile-form" action="profile-engine.php" method="post">
<input type="hidden" name="formid" value="edit-profile">
<input type="hidden" name="thisprofile" value="<?php echo $profile; ?>">
<table id="profile-detail" class="profile-form">
<tr>
<td>
<label for="profile-name">Name:</label>
<?php
$nameresult = mysql_query("SELECT ProfileName
FROM profiles
WHERE ProfileID = '$profile'");
$row = mysql_fetch_array($nameresult);
?>
<input type="text" class="text" name="profile-name" id="profile-name" value="<?php echo $row['ProfileName']; ?>" />
</td>
//goes on in this vein for another 16 inputs :)
The Search Query:
//connection established
$query = "SELECT * FROM profiles";
$postParameters = array("name","height","gender","class","death","appro","born","tobiano","modifier","adult","birth","sire","dam","breeder","owner","breed","location");
$whereClause = " WHERE 1 = 1";
foreach ($postParameters as $param) {
if (isset($_POST[$param]) && !empty($_POST[$param])) {
switch ($param) {
case "name":
$whereClause .= " AND ProfileName LIKE '%".$_POST[$param]."%' ";
break;
case "height":
$whereClause .= " AND ProfileHeight='".$_POST[$param]."' ";
break;
case "gender":
$whereClause .= " AND ProfileGenderID='".$_POST[$param]."' ";
break;
//more cases....
}
}
}
$query .= $whereClause;
$result = mysql_query("$query");
$values = array();
while ($row = mysql_fetch_array($result)) {
$values[] = $row['ProfileID'];
}
/*
//just me checking that it worked...
foreach( $values as $value => $id){
echo "$id <br />";
}
*/
mysql_close($con);
So, there you have it! Thanks in advance for any help!
what about:
search copies search term to local variable, service returns an array of results that you hold, and then pagination uses JS to drop in the values into the appropriate fields. If you change one and save, it submits the edits, including the original search term, which is used to re-query the service, and returns the updated array...repeat as necessary
here's some sample code (here there's just two search fields, I know you need more):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
var query = new Object();
var resp;
var i;
function next(on){
i=on+1;
if(i==resp.results.length){i--;}
fillForm(i);
}
function prior(on){
i=on-1;
if(i<0){i++;}
fillForm(i);
}
function fillForm(i){
document.getElementById("paginate").innerHTML='<button onclick="prior('+i+')"><</button>'+(i+1)+' of '+resp.results.length+'<button onclick="next('+i+')">></button>';
document.getElementById("name").value=resp.results[i].name;
document.getElementById("height").value=resp.results[i].height;
document.getElementById("gender").value=resp.results[i].gender;
document.getElementById("class").value=resp.results[i].class;
document.getElementById("death").value=resp.results[i].death;
document.getElementById("appro").value=resp.results[i].appro;
document.getElementById("born").value=resp.results[i].born;
document.getElementById("tobiano").value=resp.results[i].tobiano;
document.getElementById("modifier").value=resp.results[i].modifier;
document.getElementById("adult").value=resp.results[i].adult;
document.getElementById("birth").value=resp.results[i].birth;
document.getElementById("sire").value=resp.results[i].sire;
document.getElementById("dam").value=resp.results[i].dam;
document.getElementById("breeder").value=resp.results[i].breeder;
document.getElementById("owner").value=resp.results[i].owner;
document.getElementById("breed").value=resp.results[i].breed;
document.getElementById("location").value=resp.results[i].location;
document.getElementById("id").value=resp.results[i].id;
document.getElementById("saveButton").innerHTML='<button onclick="save()">Save</button>';
}
function getData(){
query.name=document.getElementById('query_name').value;
query.gender=document.getElementById('query_gender').value;
var variables='';
variables+='name='+query.name;
variables+='&gender='+query.gender;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
resp = JSON.parse(xmlhttp.responseText);
fillForm(0);
}
}
xmlhttp.open("GET","searchNav.php?"+variables,true);
xmlhttp.send();
}
function save(){
var saving="";
saving+='?q='+query;
saving+='&name='+document.getElementById('name').value;
saving+='&height='+document.getElementById('height').value;
saving+='&gender='+document.getElementById('gender').value;
saving+='&class='+document.getElementById('class').value;
saving+='&death='+document.getElementById('death').value;
saving+='&appro='+document.getElementById('appro').value;
saving+='&born='+document.getElementById('born').value;
saving+='&tobiano='+document.getElementById('tobiano').value;
saving+='&modifier='+document.getElementById('modifier').value;
saving+='&adult='+document.getElementById('adult').value;
saving+='&birth='+document.getElementById('birth').value;
saving+='&sire='+document.getElementById('sire').value;
saving+='&dam='+document.getElementById('dam').value;
saving+='&owner='+document.getElementById('owner').value;
saving+='&breed='+document.getElementById('breed').value;
saving+='&breeder='+document.getElementById('breeder').value;
saving+='&location='+document.getElementById('location').value;
saving+='&id='+document.getElementById('id').value;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
resp = JSON.parse(xmlhttp.responseText);
fillForm(0);
}
}
xmlhttp.open("GET","saveEdits.php"+saving,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="search">
<table>
<tr><td>Name:</td><td><input type="text" id="query_name" /></td></tr>
<tr><td>Gender:</td><td><input type="text" id="query_gender" /></td></tr></table>
<button onclick="getData()">Search</button>
</div>
<div id="results">
<div id="paginate"></div>
<input type="hidden" id="id" />
<table>
<tr><td>Name:</td><td><input type="text" id="name" /></td></tr>
<tr><td>Height:</td><td><input type="text" id="height" /></td></tr>
<tr><td>Gender:</td><td><input type="text" id="gender" /></td></tr>
<tr><td>Class:</td><td><input type="text" id="class" /></td></tr>
<tr><td>Death:</td><td><input type="text" id="death" /></td></tr>
<tr><td>Appro:</td><td><input type="text" id="appro" /></td></tr>
<tr><td>Born:</td><td><input type="text" id="born" /></td></tr>
<tr><td>Tobiano:</td><td><input type="text" id="tobiano" /></td></tr>
<tr><td>Modifier:</td><td><input type="text" id="modifier" /></td></tr>
<tr><td>Adult:</td><td><input type="text" id="adult" /></td></tr>
<tr><td>Birth:</td><td><input type="text" id="birth" /></td></tr>
<tr><td>Sire:</td><td><input type="text" id="sire" /></td></tr>
<tr><td>Dam:</td><td><input type="text" id="dam" /></td></tr>
<tr><td>Breeder:</td><td><input type="text" id="breeder" /></td></tr>
<tr><td>Owner:</td><td><input type="text" id="owner" /></td></tr>
<tr><td>Breed:</td><td><input type="text" id="breed" /></td></tr>
<tr><td>Location:</td><td><input type="text" id="location" /></td></tr>
</table>
<div id="saveButton"></div>
</div>
</body>
</html>
and the search:
<?php
//connection established
$query = "SELECT * FROM profiles";
$postParameters = array("name","height","gender","class","death","appro","born","tobiano","modifier","adult","birth","sire","dam","breeder","owner","breed","location");
$whereClause = " WHERE 1 = 1";
foreach ($postParameters as $param) {
if (isset($_POST[$param]) && !empty($_POST[$param])) {
$whereClause .= " AND ".$param."='".$_POST[$param]."'";
}
}
$query .= $whereClause;
$result = mysql_query("$query");
echo "{\"results\":";
if($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "[";
echo "{\"name\":\"".$row["name"]."\",";
echo "\"height\":\"".$row["height"]."\",";
echo "\"gender\":\"".$row["gender"]."\",";
echo "\"class\":\"".$row["class"]."\",";
echo "\"death\":\"".$row["death"]."\",";
echo "\"appro\":\"".$row["appro"]."\",";
echo "\"born\":\"".$row["born"]."\"";
echo "\"tobiano\":\"".$row["tobiano"]."\"";
echo "\"modifier\":\"".$row["modifier"]."\"";
echo "\"adult\":\"".$row["adult"]."\"";
echo "\"birth\":\"".$row["birth"]."\"";
echo "\"sire\":\"".$row["sire"]."\"";
echo "\"dam\":\"".$row["dam"]."\"";
echo "\"breeder\":\"".$row["breeder"]."\"";
echo "\"owner\":\"".$row["owner"]."\"";
echo "\"breed\":\"".$row["breed"]."\"";
echo "\"location\":\"".$row["location"]."\"";
//echo "\"id\":\"".$row["id"]."\"";
echo "}";
}
else{
echo "\"no\"}";
exit;
}
while($row = mysql_fetch_array($data,MYSQL_ASSOC)){
echo ",{\"name\":\"".$row["name"]."\",";
echo "\"height\":\"".$row["height"]."\",";
echo "\"gender\":\"".$row["gender"]."\",";
echo "\"class\":\"".$row["class"]."\",";
echo "\"death\":\"".$row["death"]."\",";
echo "\"appro\":\"".$row["appro"]."\",";
echo "\"born\":\"".$row["born"]."\"";
echo "\"tobiano\":\"".$row["tobiano"]."\"";
echo "\"modifier\":\"".$row["modifier"]."\"";
echo "\"adult\":\"".$row["adult"]."\"";
echo "\"birth\":\"".$row["birth"]."\"";
echo "\"sire\":\"".$row["sire"]."\"";
echo "\"dam\":\"".$row["dam"]."\"";
echo "\"breeder\":\"".$row["breeder"]."\"";
echo "\"owner\":\"".$row["owner"]."\"";
echo "\"breed\":\"".$row["breed"]."\"";
echo "\"location\":\"".$row["location"]."\"";
//echo "\"id\":\"".$row["id"]."\"";
echo "}";
}
echo "]}";
?>