What is the best to insert IF s. after ($r = mysql_fetch_...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
szmitek
Forum Newbie
Posts: 1
Joined: Tue Oct 16, 2007 5:34 am
Location: Chotomów, Poland

What is the best to insert IF s. after ($r = mysql_fetch_...

Post by szmitek »

What is the best to insert IF statement after

Code: Select all

while ($r = mysql_fetch_array($w)) {
like? I would like in order that

Code: Select all

<comments>'.$site_adres."news.php?id=".$r['url'].'</comments>
was showed only if

Code: Select all

$r["comm"] = '1'
Script:

Code: Select all

<?php header("Content-type: application/rss+xml"); header("Accept-Encoding: iso-8859-2"); echo '<?xml version="1.0" encoding="iso-8859-2" ?>';
?>

<rss version="2.0">
  <channel>
    <title>Aktualno&#347;ci LO im. Jose Marti w Warszawie</title>
    <link>http://josemarti.waw.pl</link> 
    <description>Szkolne aktualno&#347;ci</description>
    <language>pl</language>
    <managingEditor>szmitek@hotmail.com (Kamil Szmit)</managingEditor>
    <webMaster>szmitek@hotmail.com (Kamil Szmit)</webMaster>
    <copyright>Wszelkie prawa zastrze&#380;one. All rights reserved</copyright>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
<?php require_once('mwc.php'); $w = mysql_query("SELECT data.*, cat.ID AS cat_ID, cat.title AS cat_title, user.ID, user.name, user.email FROM $GLOBALS[news_data_tbl] data, $GLOBALS[news_cat_tbl] cat, $GLOBALS[users_tbl] user WHERE data.stat='1' AND data.ID2 = cat.ID AND data.user_id = user.ID ORDER BY data.date DESC"); while ($r = mysql_fetch_array($w)) {echo '    <item>
     <title>'.$r['title'].'</title>
     <link>'.$site_adres."news.php?id=".$r['url'].'</link>
     <pubDate>'.date("r", $r["date"]).'</pubDate>
     <description><![CDATA['.str_replace(array("../", 'href="plan', 'href="galery'), array($site_adres, 'href="'.$site_adres."plan", 'href="'.$site_adres."galery"), $r["text"]).']]></description>
     <author>'.$r["email"].' ('.$r["name"].')</author>
     <category>'.$r["cat_title"].'</category>
     <guid isPermaLink="true">'.$site_adres."news.php?id=".$r['url'].'</guid>
     <comments>'.$site_adres."news.php?id=".$r['url'].'</comments>
    </item>
';} ?>
 </channel>
</rss>
This

Code: Select all

$w = mysql_query("SELECT data.*, cat.ID AS cat_ID, cat.title AS cat_title, user.ID, user.name, user.email FROM $GLOBALS[news_data_tbl] data, $GLOBALS[news_cat_tbl] cat, $GLOBALS[users_tbl] user WHERE data.stat='1' AND data.ID2 = cat.ID AND data.user_id = user.ID ORDER BY data.date DESC");while ($r = mysql_fetch_array($w)) {        echo '    <item>     <title>'.$r['title'].'</title>     <link>'.$site_adres."news.php?id=".$r['url'].'</link>     <pubDate>'.date("r", $r["date"]).'</pubDate>     <description><![CDATA['.str_replace(array("../", 'href="plan', 'href="galery'), array($site_adres, 'href="'.$site_adres."plan", 'href="'.$site_adres."galery"), $r["text"]).']]></description>     <author>'.$r["email"].' ('.$r["name"].')</author>     <category>'.$r["cat_title"].'</category>     <guid isPermaLink="true">'.$site_adres."news.php?id=".$r['url'].'</guid>';     if($r["comm"] == '1'){        echo '<comments>'.$site_adres."news.php?id=".$r['url'].'</comments>';     }    echo '</item>';}
does not work properly.

Code: Select all

<comments>'.$site_adres."news.php?id=".$r['url'].'</comments>
is showed for all items instead for items which

Code: Select all

$r["comm"] = '1'
because first item has

Code: Select all

$r["comm"] = '1'
How to do this better?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Maybe add " AND comm = '1' " to the WHERE clause?
(#10850)
Post Reply