Ok, so i have a basic page with source that looks something like this:
index.php
<html>
<head>
<title>Ajap Test</title>
<script language="JavaScript" src="../../unavailable.html"></script>
</head>
<body>
This page loads content asychronously.
<a href="../../unavailable.html">Click here to load red data.</a>
<a href="../../unavailable.html">Click here to load blue data.</a>
<div id="loadspace1">
</div>
</body>
</html>
This references a php file, masquerading as a java script file, in order to load data from the server, in a similar style to AJAX, but without and XML, just php, hence "AJAP".
I use a PHP file to query a MySQL database, and return the results of the query using JavaScript.
However my problem is that i can't dynamically change the MySQL query from index.php
script.php
<?php
$supplier = $_REQUEST['s'];
include("connect.inc.php");
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM products WHERE supplier='$supplier' ORDER BY name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
$data='';
mysql_close();
while ($i < $num) {
$productname=mysql_result($result,$i,"name");
$data= $data."
".$productname;
$i++;
}
echo<<<END
function dataload(id,color){
var data="$data";
document.getElementById(id).innerHTML = data;
document.getElementById(id).style.color = color;
}
END;
?>
Now you can see that in index.php i can pass a static variable to script.php, by appending ?s=Alex to the URL. However, i want to be able to pass a dynamic variable to script.php, so that the script will select different items from the database depending on that variable, and load them into the page without reloading.
To put it into context, this database contains a load of items with a value assigning them to different categories.
I want to load items onto the page, AJAX style, but i want the user to be able to choose which category of items is loaded. In order for the correct items to be loaded, i need to pass different values to the PHP so that the MySQL functions will select the right data. Sending the value in the head of the script means i can't change it without reloading the page, which would defeat the whole point of doing this.
Does anybody know a way i might be able to do this?
Thanks in advance.
Aqua-Soft Forums