开发者

PHP - while loop change

开发者 https://www.devze.com 2023-03-26 16:15 出处:网络
I have following while loop. $readNews_SQLselect = \"SELECT\"; $readNews_SQLselect .= \"id, content \";// rows names

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 str开发者_Python百科ing of '0' should be displayed? Live will be either 0 / 1 (VARCHART).

Any suggestion much appreciated.


Just add this to your query:

$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


  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>'; }

0

精彩评论

暂无评论...
验证码 换一张
取 消