Click to See Complete Forum and Search --> : What is the best to insert IF statement after while ($r = mysql_fetch_array($w)) {


szmitek
10-16-2007, 05:29 AM
What is the best to insert IF statement after while ($r = mysql_fetch_array($w)) { like? I would like in order that <comments>'.$site_adres."news.php?id=".$r['url'].'</comments> was showed only if $r["comm"] = '1'
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>

bokeh
10-16-2007, 03:02 PM
while ($r = mysql_fetch_array($w))
{
if('1' === $r["comm"])
{
echo "<comments>{$site_adres}news.php?id={$r['url']}</comments>";
}
}Also, work on making your code look nice, something you can be proud of.

szmitek
10-16-2007, 07:00 PM
Thank you Brohen! It works (RSS feed (http://www.josemarti.waw.pl/rss)).

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>
';
if('1' === $r["comm"]){echo ' <comments>'.$site_adres.'news.php?id='.$r['url'].'</comments>
';}
echo ' </item>
';} ?>
</channel>
</rss>

szmitek
10-16-2007, 07:01 PM
aa

NightShift58
10-16-2007, 07:41 PM
Also, work on making your code look nice, something you can be proud of.
<?php
WHILE ($r = mysql_fetch_array($w)) :
IF ('1' === $r["comm"]) :
echo "<comments>{$site_adres}news.php?id={$r['url']}</comments>";
ENDIF;
ENDWHILE;
?>???