使用cookie获取id,对匹配字段执行内连接


Use cookie to get id, perform inner join on matching fields

这是我的第一篇文章,但是我发现这个论坛非常有用!我希望你能帮助我。

我的难题是:我让用户登录,然后互相评分。一旦用户登录,我希望他们能够看到他们所做的评级(这个我正在工作-我可以通过表单生成的唯一id选择评论),还可以看到他们收到的评级摘要。这似乎是棘手的地方。我尝试了一个内连接,但它没有产生任何结果。

现在我把这部分放在html

上面
<?php 
    include "connect.php";
    if(isset($_COOKIE['ID_my_site'])) 
    { 
        $username = $_COOKIE['ID_my_site']; 
        $pass = $_COOKIE['Key_my_site']; 
        while($info = mysql_fetch_array( $check ))   
        { 
            //if the cookie has the wrong password, they are taken to the login page 
            if ($pass != $info['password']) 
            {
                header(""); 
            } 
            //otherwise they are shown the admin area    
            else 
            {
                echo ""; 
                echo ""; 
            } 
        } 
    } 
     else 
    //if the cookie does not exist, they are taken to the login screen 
    {            
        header(""); 
    } 
include "settings.php";
?>

在我的html

之后
<?php
    include('connect.php');
    $result = mysql_query("SELECT r.user, r.rating1, r.rating2, r.rating3, u.username
                             FROM reviews r INNER JOIN users u ON r.user=u.username
                            WHERE r.user='$userid' ORDER BY r.user DESC") 
                or die(mysql_error()); 
        echo "<table border='1' cellpadding='10'>";
        echo "<tr>
                  <th></th>
                  <th>View Comments</th>
                  <th>Rating 1</th>
                  <th>Rating 2</th>
                  <th>Rating 3</th>
              </tr>";
        while($row = mysql_fetch_array( $result )) {
               echo "<tr>";
               echo '<td><a href="showit.php?id=' . $row['id'] . '">View/Print</a></td>';
               echo '<td>' . $row['rating1'] . '</td>';
               echo '<td>' . $row['rating2'] . '</td>';
               echo '<td>' . $row['rating3'] . '</td>';
               echo "</tr>"; 
        } 
        echo "</table>";
?> 

不幸的是,我根本没有得到任何结果,尽管我在sql表中看到了这个人的20个评级。

它也抛出一个"警告:mysql_fetch_array():提供的参数不是一个有效的MySQL结果资源在views.php在第19行"错误。

里面可能有一个愚蠢的错误,但我变得码盲和沮丧。

谢谢你的帮助!

如果这是第19行:

while($row = mysql_fetch_array( $result )) {
               echo "<tr>";
               echo '<td><a href="showit.php?id=' . $row['id'] . '">View/Print</a></td>';
               echo '<td>' . $row['rating1'] . '</td>';
               echo '<td>' . $row['rating2'] . '</td>';
               echo '<td>' . $row['rating3'] . '</td>';
               echo "</tr>"; 
        } 

应该使用数组中值的位置,如1,2,3…等等,不是评级1,而是评级2…等等