所以,我真的很困惑這裏。我不知道我在做什麼,但是,我試圖限制基於網絡的搜索是私有的還是公共的。第二次嘗試限制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