隐藏/显示按钮,也在刷新时 [英] Hide/Show button, also when refreshed

查看:98
本文介绍了隐藏/显示按钮,也在刷新时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个显示活动"的应用程序.每个活动都有自己的按钮.当您单击该按钮时,会将特定活动添加到指南"中.这样的想法是,您只能添加一个特定的活动一次,因此该活动的按钮在添加到指南中时必须消失.我可以在JavaScript中使用简单的$(this).hide(),但是刷新页面时显然不起作用.所以我想我应该检查一下活动是否存在于de guide中.

I am making an application that displays "activities". Each activity has his own button. When you click on that button, you add that specific activity to your "guide". The idea is that you can add one specific activity only once, so the button of that activity must disapear when it's added to the guide. I can use a simple $(this).hide() in my javascript but that obviously doesn't work when I refresh the page. So I guess i should make a check if the activity exists in de guide.

我有3个表:1:activity(带有ActivityID),2:user(带有UserID)和3:user_activity(带有ActivityID,一个链接表).

in the database I have 3 tables, 1: activity (with an ActivityID), 2: user (with a UserID) and 3: user_activity (with ActivityID and UserID, a linktable).

因此,检查必须检查user_activity表中是否存在ActivityID,并且user_activity表中属于该ActivityIDUserID与当前用户的ID相同.

So the check must check if the ActivityID exists in the user_activity table, and that the UserID that belongs to that ActivityID in the user_activity table is the sames as the current users' ID.

此刻,我知道如何检查当前用户的UserID:

At this moment, I know how to check the current users UserID:

//userid
$sql = "SELECT * FROM user WHERE Username = '".$_SESSION['Username']."' ";
$stm = $db->prepare($sql);
$result = $stm->execute(array());
while($row = $stm->fetch(PDO::FETCH_ASSOC)) {
$userid = $row['UserID'];
}

但是我不知道如何检查ActivityID是否已经存在,以及我应该如何做 如果是其他语句.

But I don't know how to check if the ActivityID already exists, and how I should make this if else statement.

当我使用此脚本显示活动(包括按钮)时

Ay the moment I use this script to display the activity (incl. the button)

$sql = "SELECT * FROM activity";
$stm = $db->prepare($sql);
$result = $stm->execute(array());   

while($row = $stm->fetch(PDO::FETCH_ASSOC))
{
    echo '<div id="activity'.$row['ActivityID'].'">';
    echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['ActivityIMG'] ) . '" >', '<br>';
    $instantguide = $row['ActivityID'];
    echo '<input type="button" class="addActivity" onclick="MakeRequest(' . $instantguide . ')" value="Activiteit toevoegen" data-activity="' . $row['ActivityID'] . '">';
    echo '</div>';
}

推荐答案

您需要左联接才能查看已有的活动

You need a LEFT JOIN to see what activities are already on

SELECT a.*, ua.ActivityID as added 
FROM activities a LEFT JOIN user_activity ua 
    ON a.ActivityID=ua.ActivityID AND UserID=:userid

因此,结果集中将有一个附加的added字段,如果已选择,则填充一个ID,否则为空

So you'll have an additional added field in the resultset, filled with an id if it is already chosen or empty otherwise

这篇关于隐藏/显示按钮,也在刷新时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆