Trying to use ajax to sync up with the database but never really got it to work unless i refresh the page.
<!-- the html page -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/generalFunctions.js"></script>
<script src="php_lib/getOrder.php"></script>
</head>
<body>
<script type="text/javascript">
// a function in the "js/generalFunctions.js", the ajax function, see below
getContent("./php_lib/getOrder.php");
</script>
</body>
</html>
//my ajax code
var asyncRequest;
var data = "table=table_for_testing&res_name=name_for_testing";
function getContent(url)
{
try
{
asyncRequest = new XMLHttpRequest();
asyncRequest.onreadystatechange = stateChange;
asyncRequest.open('POST', url, true);
//////////////// newly added for php parsing ///////////////////////
////// Send the proper header information along with the request ////////////
asyncRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
asyncRequest.setRequestHeader("Content-length", data.length);
asyncRequest.setRequestHeader("Connection", "close");
//////////////////////////////////////////////////////////////////////////////
asyncRequest.send(data);
}
catch(exception)
{
alert('Request Failed.');
}
}
function stateChange()
{
if(asyncRequest.readyState == 4 && asyncRequest.status == 200)
{
document.getElementById('contentArea').innerHTML = asyncRequest.responseText;
}
}
// you may assume my php code is correct, i tested it. just post it anyway if it is needed
<?php
include('config.php');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
/*
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
else
{
echo "Successfully connected to server";
}
*/
//Select database
$db = mysql_select_db(DB_DATABASE);
/*
if(!$db)
{
die("Unable to select database");
}
else
{
echo "connected to database";
}
*/
$sql_t1=mysql_query("select orderline.quantity, menu.item_name, menu.price
from orderline, menu, orders
where orderline.item_id = menu.item_id
and orders.order_id = orderline.order_id
and orders.table_num = 'table1'
and orders.order_status = 0; ");
$sql_t2=mysql_query("select orderline.quantity, menu.item_name, menu.price
from orderline, menu, orders
where orderline.item_id = menu.item_id
and orders.order_id = orderline.order_id
and orders.table_num = 'table2'
and orders.order_status = 0; ");
$sql_t3=mysql_query("select orderline.quantity, menu.item_name, menu.price
from orderline, menu, orders
where orderline.item_id = menu.item_id
and orders.order_id = orderline.order_id
and orders.table_num = 'table3'
and orders.order_status = 0;");
$sql_t4=mysql_query("select orderline.quantity, menu.item_name, menu.price
from orderline, menu, orders
where orderline.item_id = menu.item_id
and orders.order_id = orderline.order_id
and orders.table_num = 'table4'
and orders.order_status = 0; ");
echo "<table border=\"0\" align=\"center\"><tr><td>"; // open outter table
//////////////////////// Table 1 ///////////////////////////////
echo "<table border=\"1\" background=\"images/blueStripe.png\"><th>Quantity</th><th>Item</th><th>Price</th>";
echo "<caption>Table 1</caption>";
while($row=mysql_fetch_array($sql_t1))
{
$quantity = $row['quantity'];
$item = $row['item_name'];
$price = $row['price'];
echo "<tr>";
echo "<td>$quantity</td>";
echo "<td>$item</td>";
echo "<td>$price</td>";
echo "</tr>";
}
echo "</table>";
echo "</td>"; // outter table
////////////// table 2 ///////////////
echo "<td>"; // outter table
echo "<table border=\"1\" background=\"images/blueStripe.png\"><th>Quantity</th><th>Item</th><th>Price</th>";
echo "<caption>Table 2 </caption>";
while($row=mysql_fetch_array($sql_t2))
{
$quantity = $row['quantity'];
$item = $row['item_name'];
$price = $row['price'];
echo "<tr>";
echo "<td>$quantity</td>";
echo "<td>$item</td>";
echo "<td>$price</td>";
echo "</tr>";
}
echo "</table>";
echo "</td>"; // outter table
//////////////// Table 3 //////////////////////
echo "<td>"; // outter table
echo "<table border=\"1\" background=\"images/blueStripe.png\"><th>Quantity</th><th>Item</th><th>Price</th>";
echo "<caption>Table 3 </caption>";
while($row=mysql_fetch_array($sql_t3))
{
$quantity = $row['quantity'];
$item = $row['item_name'];
$price = $row['price'];
echo "<tr>";
echo "<td>$quantity</td>";
echo "<td>$item</td>";
echo "<td>$price</td>";
echo "</tr>";
}
echo "</table>";
echo "</td>"; // outter table
//////////////// Table 4 //////////////////////////
echo "<td>"; // outter table
echo "<table border=\"1\" background=\"images/blueStripe.png\"><th>Quantity</th><th>Item</th><th>Price</th>";
echo "<caption>Table 4 </caption>";
while($row=mysql_fetch_array($sql_t4))
{
$quantity = $row['quantity'];
$item = $row['item_name'];
$price = $row['price'];
echo "<tr>";
echo "<td>$quantity</td>";
echo "<td>$item</td>";
echo "<td>$price</td>";
echo "</tr>";
}
echo "</table>";
echo "</td>"; // outter table
echo $_POST['data'];
echo $_POST['res_name'];
/////// end table///////////
echo "</tr></table>"; // close outter table
?>
thanks very much!