1

我有一个网站,用户可以在其中加入群组并发布与该群组相关的主题,我遇到了一个问题,无论用户结果如何,即使在数据库中没有记录的测试帐户上,它也只会显示“成员”,有人可以吗请解释我做错了什么,谢谢。

<?php
$id = $_GET['gid'];
$user = $_SESSION['user_id'];

$iropen = "SELECT * FROM `group_users` WHERE user_id='$user' AND group_id='$id'"; 
$resultg = mysql_query($iropen);
$rows = mysql_fetch_array($resultg);

if ($rows['accepted'] = 1) {
    echo 'member';
} else {
    echo 'pending';
}
if ($resultg < 1) {
    echo 'join';
}
?>
4

4 回答 4

7
if ($rows['accepted'] = 1) {

You need two == here.

if ($rows['accepted'] == 1) {

PHP's operator reference, if you need it: http://www.php.net/manual/en/language.operators.php

于 2013-09-09T03:33:17.113 回答
1

@vinodadhikary 的意思是您的第一个 IF 子句中有单个等号而不是双等号。应该是:如果 ($rows['accepted'] == 1)...

于 2013-09-09T03:37:41.000 回答
0

尝试这个

<?php
$id = $_GET['gid'];
$user = $_SESSION['user_id'];

$iropen = "SELECT * FROM `group_users` WHERE user_id='".$user."' AND group_id='".$id."'"; 
if($resultg = mysql_query($iropen)){
     $rows = mysql_fetch_array($resultg)
}

if (mysql_num_rows($resultg) < 1) {
    echo 'join';
}else if ($rows['accepted'] == 1) {
    echo 'member';
} else {
    echo 'pending';
}

?>
于 2013-09-09T05:03:14.940 回答
0
<?php
    $id = $_GET['gid'];
    $user = $_SESSION['user_id'];

    $iropen = "SELECT * FROM `group_users` WHERE user_id='$user' AND group_id='$id'"; 
    $resultg = mysql_query($iropen);
    $rows = mysql_fetch_array($resultg);
    $num_results = mysql_num_rows($resultg);


    if ($num_results < 1) {
        echo "join";
    } else if ($rows['accepted'] == 1) {
        echo "member";
    } else {
        echo "pending";
    }
?>
于 2013-09-09T05:23:02.973 回答