As my question seems common but I refer my question on stackoverflow but did not get my solution.I refer How to avoid page refreshing on anchor (<a></a>) tag click? link also.
My Problem:
I am using two dropdown for filtering data. I have been done with the filtration and got data according to result in data table. Now I have three action on data table with anchor tag. When I clicked on that anchor tag my filtered data will not maintain and it clear result.
Kindly help me out of this problem.
My code snippet: For two dropdown
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<div class="controls col-md-3">
<select required id='selectError2' placeholder='select Category' class='form-control' name='category'>
<option value=''>Select Category</option>
<?php
include("db.php");
$sql="SELECT * FROM category";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo "<option value='". $row['category_name'] ."' >". $row['category_name'] ." </option>";
}
?>
</select>
</div>
<div class="controls col-md-3">
<select required id='selectError2' placeholder='select subcategory' class='form-control' name='subcategory'>
<option value=''>Select SubCategory</option>
<?php
include("db.php");
$sql="SELECT * FROM subcategory";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo "<option value='". $row['subcategory_name'] ."'>". $row['subcategory_name'] ."</option>";
}
?>
</select>
</div>
<div class="controls col-md-2">
<input type="submit" class="btn btn-default" name="btn_submit" style="font-weight:bold" value="GO"/>
</div>
</form>
</tr>
</thead>
</table>
My other data table part is:
<?php
while($row = mysql_fetch_array($result)){
/* other stuff */
<a class='btn btn-danger' href='product_delete.php?product_id=". $row['product_id'] ."'>
<i class='glyphicon glyphicon-edit icon-white'></i>Delete
</a>
</td>
$query1 = "query"; //You don't need a ; like you do in SQL
$result1 = mysql_query($query1);
$count=mysql_num_rows($result1);
if($count == 1){
echo"<td style='text-align:center'>
<a href='unpublished_product.php?product_id=". $row['product_id'] ."'>
<img alt='' src='/admin/img/published.png' style='width:30px;height:30px;' />
</a>
</td>";
}
else {
echo"<td style='text-align:center'>
<a href='published_product.php?product_id=".$row['product_id']."'>
<img alt='' src='/admin/img/unpublished.png' id=' ". $row['product_id'] . "' onclick='atualiza()' style='width:30px;height:30px;' />
</a>
</td>";
}
echo"</tr>";
}
?>
<a href="URL"> will always change your location ...
What do you want to achive is simply to use Ajax mechanism, so update your code with someting like this :
<a href="javascript:void(0)" onclick="YOUR_JS_FUNCTION();">Link</a>
and YOUR_JS_FUNCTION() will do Asynchronous request to your server (published_product.php?product_id=xxxx)
Thre are thousands of examples on the internet that show you how to use Ajax with or without additional frameworks
You can find here an example using JQuery
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With