[英]IF statement not sure what I am doing wrong
Before I start I am learning PHP/Mysql, so I am trying to learn and understand all that before I move onto mysqli and researching correct security steps, so I am aware this code will have holes int it. 在开始学习PHP / Mysql之前,我会尝试学习并理解所有内容,然后再研究mysqli并研究正确的安全性步骤,因此我知道这段代码会有漏洞。
Basically I am implementing a member group system and I am trying to work out the coding so that.. 基本上,我正在实施成员组系统,并且正在尝试制定代码,以便..
IF a member is in the group, show "group member" IF a member isn't in the group, "join group" IF a member has already requested a join, but accepted is still = 0(pending) show "invite pending". 如果成员在组中,则显示“组成员”;如果成员不在组中,则显示“加入组”;如果成员已请求加入,但接受的值仍为0(待处理),则显示“邀请待处理” 。
Here is my code so far, it's inside an include. 到目前为止,这是我的代码,它包含在一个include中。
<?php
$id = $_GET['gid'];
$gruser = $_SESSION['user_id'];
$group = "SELECT * FROM `disc_users` WHERE user_id='$gruser' AND group_id='$id'";
$gres = mysql_query($group);
if ($gres == 0) { ?>
<input type="button" class="sub-button" value="Join Group">
<?
}
if ($gres == 1) { ?>
<input type="button" class="sub-button" value="Group Member">
<? } ?>
I can't figure out what I am doing wrong, it's not displaying errors, but I am getting white space, no buttons, I even added "echo" in front of $group and it's getting the values correctly. 我无法弄清楚我在做什么错,它没有显示错误,但是我得到了空格,没有按钮,我什至在$ group前面添加了“ echo”,它正确地获取了值。
Any help appreciated. 任何帮助表示赞赏。
You cant simply compare mysql_query result you have to use mysql_fetch_row etc but in your case may be like this: 您不能简单地比较必须使用mysql_fetch_row等的mysql_query结果,但是在您的情况下可能是这样的:
<?php
$id = $_GET['gid'];
$gruser = $_SESSION['user_id'];
$group = "SELECT * FROM `disc_users` WHERE user_id='$gruser' AND group_id='$id'";
$gres = mysql_query($group);
if (mysql_num_rows($gres) < 0) { ?>
<input type="button" class="sub-button" value="Join Group">
<?
}
else{ ?>
<input type="button" class="sub-button" value="Group Member">
<? } ?>
mysql queries always return as an array its not possible to compare them in a if statement before first breaking the array down in to individual variables. mysql查询总是以数组的形式返回,因此在首先将数组分解为各个变量之前,不可能在if语句中进行比较。
you can use mysql_num_rows, $num_rows = mysql_num_rows($gres);
您可以使用mysql_num_rows, $num_rows = mysql_num_rows($gres);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.