Hi there, I'm trying to create a button that toggles an sql query. I have a navigation bar with certain elements hidden by the admin, the admin can preview the page and there's a toggle button to hide or show the items that are marked as hidden.
$sql = "select href, pageid, navname, name, url from tblpage where hide<>1 and parentid=-1 and (project=0 or project is NULL) order by disorder";
if($_SESSION["userid"] > 0){
?>
<a class="navtoggle" href="javascript:"><img class="navtogimg" src="http://<?=DOMAIN?>/cms_content/images/navshow.png" width="177" height="86" alt="show hidden navigation items" /></a>
<?php
$sql = $_POST['sql'];
}
$sqlstmtt = $GLOBALS["db1"]->prepare($sql);
$sqlstmtt->execute();
My idea was to toggle the button image with jquery and change the $sql variable. Of course, client side vs. server side and all that I found out I need to use ajax. That led me to creating this function but seeing as it doesn't seem to work properly I must have something done wrong.
$(document).ready(function(){
$(".navtoggle").toggle(function(){
$(".navtogimg").attr("src","http://<?=DOMAIN?>/cms_content/images/navhide.png");
$.post("top.php", { sql: "select href, pageid, navname, name, url from tblpage where and parentid=-1 and (project=0 or project is NULL) order by disorder" });
},function(){
$(".navtogimg").attr("src","http://<?=DOMAIN?>/cms_content/images/navshow.png");
$.post("top.php", { sql: "select href, pageid, navname, name, url from tblpage where hide<>1 and parentid=-1 and (project=0 or project is NULL) order by disorder" });
})
});