What is the best to insert IF statement after while ($r = mysql_fetch_array($w)) { PHP: like? I would like in order that <comments>'.$site_adres."news.php?id=".$r['url'].'</comments> PHP: was showed only if $r["comm"] = '1' PHP: Script: <?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ści LO im. Jose Marti w Warszawie</title> <link>http://josemarti.waw.pl</link> <description>Szkolne aktualności</description> <language>pl</language> <managingEditor>szmitek@hotmail.com (Kamil Szmit)</managingEditor> <webMaster>szmitek@hotmail.com (Kamil Szmit)</webMaster> <copyright>Wszelkie prawa zastrzeż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> PHP:
the script you posted, not sure what exactly that is for? can you clarify a bit more? because from what i understand you want to insert an if statement after your while statement... and i don't see why you dont just do that? while (exp==exp) { if (exp==exp) { //code } } PHP:
When I do this like this: $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>'; } PHP: it does not work properly. <comments>'.$site_adres."news.php?id=".$r['url'].'</comments> PHP: is showed for all items instead for items which $r["comm"] = '1' PHP: because first item has $r["comm"] = '1' PHP: How to do this better?
where does the $r['comm'] come from? i think it may also be that since you are reading it as $r = mysql_fetch_array($w)) PHP: your $r['comm'] PHP: will not be changing as the fetch_array does not change the the array key->value association except in cases of 0->1->2->3 etc.
mysql_fetch_array by default will get both the numeric and associative arrays. Honestly your code looks correct to me. I'm assuming that comm is a column in the data table. I'd look at the db and make sure that the data is what you expect.