我有下面的while循环。
$readNews_SQLselect = "SELECT ";
$readNews_SQLselect .= "id, content "; // rows names
$readNews_SQLselect .= "FROM ";
$readNews_SQLselect .= "news "; // table name
$readNews_SQLselect_Query = mysql_query($readNews_SQLselect);
//$indx = 1;
while ($row = mysql_fetch_array($readNews_SQLselect_Query, MYSQL_ASSOC)) {
$ID = $row['id'];
$CONTENT = $row['content'];
echo '<li>' . $ID .' ' . $CONTENT . '</li>';
//$indx++;
}
mysql_free_result($readNews_SQLselect_Query);
如果我添加'$LIVE = $row['live'];'
的条件是只显示live
值字符串为'0'的行,它会怎么样? Live将为0/1 (VARCHART)。
只需将此添加到您的查询中:
$readNews_SQLslect .= " WHERE live = '0'";
Alter $readNews_SQLselect
$readNews_SQLselect = "SELECT ";
$readNews_SQLselect .= "id, content "; // rows names
$readNews_SQLselect .= "FROM ";
$readNews_SQLselect .= "news "; // table name
$readNews_SQLselect .= "WHERE live='0'"; // condition
-
修改sql:
$readNews_SQLselect = "SELECT "; $readNews_SQLselect .= "id, content "; // rows names $readNews_SQLselect .= "FROM "; $readNews_SQLselect .= "news "; // table name $readNews_SQLselect .= "where live = '0' ";
如果条件: if ($row['live'] == '0') { echo '<li>' . $ID .' ' . $CONTENT . '</li>'; }