HTML (When this DIV is clicked a call to searchfunction made and its id is passed)
<div class="me" id="<?php echo $row['main_cat_id'];?>" onClick="searchfunction('<?php echo $row['main_cat_id'];?>');">
<?php echo $row[ 'main_cat_name'];?>
</div>
Below is the search function; it passes the ID value of the clicked DIV to the pagegetparam.php
.
function searchfunction(param) {
//alert(param);
var xmlhttp = getXmlHttp();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (this.responseText !== null) {
var ajaxElm = document.getElementById('getparam');
ajaxElm.innerHTML = this.responseText; // append in front
//jQuery(ajaxElm).append(this.responseText);
}
}
}
xmlhttp.open("GET", "getparam.php?param=" + param, true);
xmlhttp.send();
}
And getparam.php
only passes back the ID to the same page it got it from. I've resorted to this method, because I believe there's no way to directly pass the id of the clicked div which was captured by JavaScript and assign it to a php variable.
<?php
$param=$_GET['param'];
echo $param;
?>
Now, I need the value of clicked div id to run this query below:
echo $param='<span id="getparam"></span>';
//it does echo the id in numeric like, 1 or 2 .But it doesn't help to execute the query though.
$sql= "SELECT * FROM categories,main_category WHERE categories.main_cat_id=main_category.main_cat_id AND categories.main_cat_id='$param'";
How can I get the clicked DIV id passed to the php variable $param
? Is there any other way or can anything be improved here?
$sql = "SELECT * ... AND categories.main_cat_id='".$param."'";
? – Y U NO WORK Jun 10 at 6:18