PHP - while 循环更改

发布于 2024-11-27 23:31:05 字数 727 浏览 0 评论 0原文

我有以下 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)。

任何建议都非常感激。

I have following while loop.

$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);

How would it look if I added '$LIVE = $row['live'];' with condition that only rows with live value string of '0' should be displayed? Live will be either 0 / 1 (VARCHART).

Any suggestion much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゝ杯具 2024-12-04 23:31:05

只需将其添加到您的查询中:

$readNews_SQLslect .= " WHERE live = '0'";

Just add this to your query:

$readNews_SQLslect .= " WHERE live = '0'";
嘴硬脾气大 2024-12-04 23:31:05

改变$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

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
看透却不说透 2024-12-04 23:31:05
  1. 改变你的sql:

    $readNews_SQLselect = "SELECT ";
    $readNews_SQLselect .= "id, 内容"; // 行名称
    $readNews_SQLselect .= "FROM ";
    $readNews_SQLselect .= "新闻"; //表名
    $readNews_SQLselect .= "其中 live = '0' "; 
  2. if条件:

    if ($row['live'] == '0') {
    回显'

  3. ' 。 $ID。' '。 $内容。 '
  4. ';
    }

  1. alter your sql:

    $readNews_SQLselect = "SELECT  ";
    $readNews_SQLselect .= "id, content ";  // rows names
    $readNews_SQLselect .= "FROM ";
    $readNews_SQLselect .= "news ";         // table name
    $readNews_SQLselect .= "where live = '0' "; 
  2. if condition:

    if ($row['live'] == '0') {
    echo '<li>' . $ID .' ' . $CONTENT . '</li>';
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文