I have 2 separate pages that display a different set of information. On one page (Page A), I've created a JS function that makes an AJAX query (it pulls in a PHP file that runs a sql) and sorts a table when options on that page are selected. Everything is currently working fine on this page. For the second page (Page B), I would like to be able to create a link that when clicked, will take the user to Page A and run the JS function on click. Since I'm moving over to a new page, I'm not sure how to get that function to carry over.
Any ideas on how I can go about this?
Here's the JS. When a user selects an item on a dropdown from Page B, I run showUser:
function showUser(){
var url = getURLSTring();
console.log(url);
$.ajax({
type: "GET",
url: "includes/list-process-availabilities.php?"+url,
datatype: "jsonp",
success: function(x){
$('.list-view-table').html(x);
}
});
};
The list-process-availabilities.php file is a list of SQL queries that are run based on the options selected in the dropdown menu on the page.
What I want to accomplish on Page B, is have the user taken to Page A and the function showUser is run for a specific SQL query based on the link on Page A.
The PHP is below:
$s=$_GET["s"]; // Get Square Footage
$n=$_GET["n"]; // Get Neighborhood
$sql = "SELECT ";
$sql .= "* ";
$sql .= "FROM ";
$sql .= "availabilities ";
$sql .= "WHERE ";
$sql .= "1 ";
$availablilityQuery = array("neighborhood" =>$n);
foreach($availablilityQuery as $key => $value){
if(!is_array($value)){
if($value != ''){
$sql.="and ".$key."='".$value."' ";
}
}
}
if($s == "2501")
{
$sql .=" and CONVERT(replace(sq_ft_available, ',',''),UNSIGNED INTEGER) >2501 ";
}
else if($s != "")
{
$s_array = explode("-", $s);
$sql .=" and CONVERT(replace(sq_ft_available, ',',''),UNSIGNED INTEGER) >=". $s_array[0]. " and CONVERT(replace(sq_ft_available, ',',''),UNSIGNED INTEGER) <=". $s_array[1]." ";
}
This is how I run the function on Page A:
<select name="square-footage" onchange="showUser()" id="selectSquareFootageAjax" class="square-footage-drop">
<option value="">Square Footage</option>
<option value="0-1000">0 - 1000 Sq. Ft.</option>
<option value="1001-2500">1,001 - 2,500 Sq. Ft.</option>
<option value="2501">2501 or Greater Sq. Ft.</option>
</select>