所以,我真的很困惑这里。我不知道我在做什么,但是,我试图限制基于网络的搜索是私有的还是公共的。第二次尝试限制mySQL和PHP中的搜索
此代码不起作用,但是,我试图弄清楚如何使这项工作。我如何才能使私人网络只出现在该网络中的人????????????????
$query = mysql_query("SELECT * FROM requests ORDER BY dateposted DESC");
while ($row = mysql_fetch_assoc($query)){
$network = mysql_query("SELECT * FROM network");
while ($row2 = mysql_fetch_assoc($network)) {
$display = false;
$pos = strpos($row['network'], $search);
if ($row2['visible'] == "public" and $search == "Global") {
$display = true;
} else
if ($pos == true and
($row2['visible'] == "public" or $row2['username'] == $username)) {
$display = true;
} else
if ($row2['visible'] == "private") {
$display = false;
}
}
echo $display;
if ($display == true){
echo "<div id='".$row["id"]."' class='item'>";
echo '<div style="width: 75%;">';
echo "<h4 style='display: inline;'>".$row["user"]." requests:</h4><br/>";
echo "<h2 style='display: inline;'>".$row["title"]." </h2>";
echo '</div>';
echo '<h3 id="button" style="border-radius: 10px; padding: 4px; color: white; float: right; position: relative; top: -50px; border: 2px solid grey; background-color: #C0504D;">Apply</h2>';
echo "</div>";
}
}
网络架构:
network text utf8_general_ci No
username text utf8_general_ci No
visible text utf8_general_ci No
的请求模式:
id int(11) No auto_increment
user text utf8_general_ci No
title text utf8_general_ci No
description text utf8_general_ci No
picture text utf8_general_ci No
price text utf8_general_ci No
premium datetime No
type text utf8_general_ci No
network text utf8_general_ci No
dateposted datetime No
我无法发现一个明显的错误,但是如果您在预期错误时得到真正的结果(或反之亦然),请检查您在strpos($ row ['network'],$ search) )值得注意的是(尽管它并不适用于这种情况),如果strpos可以给出意想不到的结果不使用精确比较(===或!==),因为当返回的0对于在位置0处找到的字符串确实是'真'结果时可以评估为'假'。 – fred2 2012-03-06 02:37:50