Because of the layout I can't use another <form> tag so I am trying to use javascript to update the database.
Since the code is just changing the URL with window.location.href it's not reloading the page to run the if statement.
Here is my code:
$check_view = $member->getUsersView($user_id);
if((isset($_GET['view-all'])) && $check_view != $_GET['view-all'])
{
$view_all = $_GET['view-all'];
$database->query('UPDATE users SET view_all = :viewall WHERE id = :userid', array(':viewall' => $view_all, ':userid' => $user_id));
}
<div onclick="javascript:window.location.href = \'page.php?action=list&'.(isset($_GET['view-all']) && $_GET['view-all']=="No" && $check_view=="No" ? 'view-all=Yes' : 'view-all=No').'\';">'.(isset($_GET['view-all']) && $_GET['view-all']=="No" && $check_view=="No" ? 'Show All' : 'Hide').'</div>
Anyone able to give me a hand with this?
EDIT: Thanks to the help of Matt I was able to get it working:
if(isset($_GET['view-all']))
{
$check_view = $member->getUsersView($user_id);
if($check_view != $_GET['view-all'])
{
$view_all = $_GET['view-all'];
$database->query('UPDATE users SET view_all = :viewall WHERE id = :userid', array(':viewall' => $view_all, ':userid' => $user_id));
}
}
$users_view = $member->getUsersView($user_id);
$view_all = "No";
$hide_show = "Hide";
if((isset($_GET['view-all']) && ($_GET['view-all']=="No")) || ($users_view=="No"))
{
$view_all = "Yes";
$hide_show = "Show All";
}
$data = '<a href="page.php?action=list&view-all='.$view_all.'">'.$hide_show.'</a>';
<div>+ onclick instead of just a regular<a>?onclickfunction in a<script>block and then call the function from there!