ST3VO
asked on
Assistance needed with php code
Hi all,
I am having problem trying to put some code together.
I have the following code:
...
$query = "select * from tbl_news ORDER BY id DESC" ;
$result = mysql_query($query) or die("Query failed") ;
...
I then have this code:
$url_product = mysql_result($result,$i,'n ews_title' );
which is displaying my domain name and the news title from the database like this:
www.mydomain.comthe-news-title-here ... now...I need to change it to do the following:
www.mydomain.com/news/fullnewsfile.php?news_title=
So, $url_product = mysql_result($result,$i,'n ews_title' ); is dispalying:
this: www.mydomain.comthe-news-title-here
I need to add a "/" after the "www.mydomain.com then this path "news/fullnewsfile.php?new s_title=" and after that the "news_title" field from the database.
Hope I've explained properly.
thanks
st3vo
I am having problem trying to put some code together.
I have the following code:
...
$query = "select * from tbl_news ORDER BY id DESC" ;
$result = mysql_query($query) or die("Query failed") ;
...
I then have this code:
$url_product = mysql_result($result,$i,'n
which is displaying my domain name and the news title from the database like this:
www.mydomain.comthe-news-title-here ... now...I need to change it to do the following:
www.mydomain.com/news/fullnewsfile.php?news_title=
So, $url_product = mysql_result($result,$i,'n
this: www.mydomain.comthe-news-title-here
I need to add a "/" after the "www.mydomain.com then this path "news/fullnewsfile.php?new
Hope I've explained properly.
thanks
st3vo
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect thanks :o)
ASKER
I just have a small problem with the code.
For example...The records are 1 foward so...title1 links to record 2 title2 links to record 3 and so on..
Is that hard to fix pls?
For example...The records are 1 foward so...title1 links to record 2 title2 links to record 3 and so on..
Is that hard to fix pls?
Could you post the full code please it's probably something obvious
ASKER
Sure here is the full code
p.s. There are lots of commented code.
thanks
see code attached.
thx
p.s. There are lots of commented code.
thanks
see code attached.
thx
<?php
// Insert here the the title of your feed
$rss_title= "mysite.com RSS feed";
// Insert your site, in the format site.com
$rss_site= "mysite.com" ;
// Insert the description of your website
$rss_description= "Mysite News RSS feed";
// Applicable language of the feed. For spanish, change to "es"
$rss_language="en";
// Address of the logo file. It can be called whatever you want it to be!
$rss_logo="http://www.".$rss_site."/images/rss.jpg";
// the feed's author email
$emailadmin="st3vo@mysite.com";
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=iso-8859-1");
// Open the database
//My local DB
//mysql_connect("localhost","root","");
//@mysql_select_db("db2") or die("Unable to select DB");
// Select all the records from the Articles/Blog table - whatever you're using it for
$query = "select * from tbl_news ORDER BY id DESC" ;
$result = mysql_query($query) or die("Query failed") ;
echo
'<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'.$rss_title.'</title>
<link>http://www.'.$rss_site.'</link>
<description>'.$rss_description.'</description>
<language>en-en</language>
<image>
<url>'.$rss_logo.'</url>
<title>'.$rss_site.'</title>
<link>http://www.'.$rss_site.'</link>
</image>';
if($rows=mysql_num_rows($result)) //new
{ //new
for($x=i;$i<$rows;$i++) //new
//for($i=0;$i<6; $i++) //will loop through 6 times to generate 6 RSS items
{
$photo_name = 'http://www.mysite.com/photo/me.gif';
$subject = mysql_result($result,$i,'news_title'); //subject line for the RSS item
$urlData = mysql_fetch_array($result); //new
$url_product = "/news/fullnews.php?news_title=".urlencode($urlData['news_title']); //new
// Define a description of the item
$description = mysql_result($result,$i,'full_story');
// Clean the description
$description = str_replace ("&","",htmlspecialchars(strip_tags($description)));
// Pass tags to describe the product - this has been left ouf of this example
$rss_tags = 'tag1, tag2';
//This is a teaser of your article, basically what RSS readers will show the user in their inbox.
//This is how you entice users to come over and read the full article
//the easiest way is to just take the first few hundred characters of the content (description)
$short_description = substr($description,0,500) . "...";
//so you can define when it was published
$timestamp = mysql_result($result,$i,'thedate');
//cleans the timestamp into an RSS friendly format
$pubdate = date("r", strtotime($timestamp));
//outputs the RSS item
echo
'
<item>
<title>'.$subject.'</title>
<link>http://www.'.$rss_site.$url_product.'</link>
<guid isPermaLink="true">http://www.'.$rss_site.$url_product.'</guid>
<description>'.$short_description.'</description>
<pubDate>'.$pubdate.'</pubDate>
</item>
';
} //end of the for-loop
} //new
mysql_close(); //close the DB
echo //close the XML file
' </channel>
</rss>';
?>
When you call "mysql_fetch_array()" it puts the information from the current row of the DB and puts into the variable it's assigned to, it then calls the next row so there is no need to use "mysql_result()" each time which is then moving the DB pointer forward 1.
I've replaced the code below
after $dbData = mysql_fetch_array($result) ; //new
if you put print_r($dbData);
it will show you exactly what I mean
Kind regards
James
I've replaced the code below
after $dbData = mysql_fetch_array($result)
if you put print_r($dbData);
it will show you exactly what I mean
Kind regards
James
<?php
// Insert here the the title of your feed
$rss_title= "mysite.com RSS feed";
// Insert your site, in the format site.com
$rss_site= "mysite.com" ;
// Insert the description of your website
$rss_description= "Mysite News RSS feed";
// Applicable language of the feed. For spanish, change to "es"
$rss_language="en";
// Address of the logo file. It can be called whatever you want it to be!
$rss_logo="http://www.".$rss_site."/images/rss.jpg";
// the feed's author email
$emailadmin="st3vo@mysite.com";
// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=iso-8859-1");
// Open the database
//My local DB
//mysql_connect("localhost","root","");
//@mysql_select_db("db2") or die("Unable to select DB");
// Select all the records from the Articles/Blog table - whatever you're using it for
$query = "select * from tbl_news ORDER BY id DESC" ;
$result = mysql_query($query) or die("Query failed") ;
echo
'<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'.$rss_title.'</title>
<link>http://www.'.$rss_site.'</link>
<description>'.$rss_description.'</description>
<language>en-en</language>
<image>
<url>'.$rss_logo.'</url>
<title>'.$rss_site.'</title>
<link>http://www.'.$rss_site.'</link>
</image>';
if($rows=mysql_num_rows($result)) //new
{ //new
for($x=i;$i<$rows;$i++) //new
//for($i=0;$i<6; $i++) //will loop through 6 times to generate 6 RSS items
{
$photo_name = 'http://www.mysite.com/photo/me.gif';
$dbData = mysql_fetch_array($result); //new
$url_product = "/news/fullnews.php?news_title=".urlencode($dbData['news_title']); //new
$subject = $dbData['news_title']; //subject line for the RSS item
// Define a description of the item
$description = $dbData['full_story'];
// Clean the description
$description = str_replace ("&","",htmlspecialchars(strip_tags($description)));
// Pass tags to describe the product - this has been left ouf of this example
$rss_tags = 'tag1, tag2';
//This is a teaser of your article, basically what RSS readers will show the user in their inbox.
//This is how you entice users to come over and read the full article
//the easiest way is to just take the first few hundred characters of the content (description)
$short_description = substr($description,0,500) . "...";
//so you can define when it was published
$timestamp = $dbData['thedate']
//cleans the timestamp into an RSS friendly format
$pubdate = date("r", strtotime($timestamp));
//outputs the RSS item
echo
'
<item>
<title>'.$subject.'</title>
<link>http://www.'.$rss_site.$url_product.'</link>
<guid isPermaLink="true">http://www.'.$rss_site.$url_product.'</guid>
<description>'.$short_description.'</description>
<pubDate>'.$pubdate.'</pubDate>
</item>
';
} //end of the for-loop
} //new
mysql_close(); //close the DB
echo //close the XML file
' </channel>
</rss>';
?>
ASKER
Perfect!!! Thanks a million for all your help! :o)
$result = mysql_query($query) or die("Query failed") ;
$urlData = mysql_fetch_array($result)
$url_product = "http://www.mydomain.com/news/fullnewsfile.php?news_title=".urlencode($urlData['new