简体   繁体   English

为什么我的查询结果重复3次?

[英]Why does my query result repeat 3 times?

the code i have below basically behaves as a friend search engine where you can add someone if you don't have them on you account. 我下面的代码基本上起着朋友搜索引擎的作用,如果您的帐户中没有他们,则可以在其中添加某人。 So i am trying to do the following: If exists it should just display the friend and if not then it should say add friend. 因此,我尝试执行以下操作:如果存在,则应仅显示朋友,如果不存在,则应显示添加朋友。

I got it to work but the tail end of the query (please see this comment "//Problem code - when i use this echo below this where it repeats 3 times") is giving me trouble where it repeats Add 3 times. 我可以使用它,但是查询的末尾(请查看此注释“ //问题代码-当我在此重复以下3次时使用此回显”)使我麻烦,重复3次。

<?php
$num_rows1 = mysql_num_rows($result);
if ($result == "") {
    echo "";
}
echo "";

$rows = mysql_num_rows($result);
if ($rows == 0) {
    print("<div id=norequests>No results for <strong>$q
                 </strong></div>");

}
elseif ($rows > 0) {
    while ($row = mysql_fetch_array($query))
    {

        $person  = htmlspecialchars($row['full_name']);
        $linksys = htmlspecialchars($row['name']);
        $pid     = htmlspecialchars($row['system_id']);
    }

    print("");
}

}


else{
    echo '<div id="error">No results.</div>';
}

$sql    = "SELECT `Friend_id` from `friends_container` 
                 WHERE `System_id` = '$sid'";
$result = mysql_query($sql);
$query = mysql_query($sql) or die("Error: " . mysql_error());

if ($result == "") {
    echo "";
}
echo "";

$rows = mysql_num_rows($result);
if ($rows == 0) {
    print("");

}
elseif ($rows > 0)
{
    while ($row = mysql_fetch_array($query))
    {
        $existing = htmlspecialchars($row['Friend_id']);
        if ($existing == $pid) {
            echo("<img src=$linksys />$person - Already Existing");
        }

        else
            //Problem code - when i use this echo below this where it repeats 3 times
        {
            echo("Add $person");
        }
    }
?>

You must have 3 images stored for each account . 每个account必须存储3 images

Your query will always result in a multiple result. 您的查询将始终导致多个结果。 what you should do is use php to convert it to something which will result in a better option or say convert the result in an array for convenience. 您应该做的是使用php将其转换为将导致更好的选择的内容,或者为了方便起见将结果转换为数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM