Page 1 of 1

need help setting a php variable

Posted: Mon Jun 06, 2011 9:15 pm
by mathruD
this will be probably be an easy question for some of you, but i am having a problem assigning a string to a php variable. i have several rss feeds stored in a database. the stored info includes the rss feed name, link to the actual site, link for just the rss for the site, etc...

i am running a do/while loop to output the rss feeds. the output is simply the title of the site and the 8 most recent articles from the site. everything is outputting fine, in terms of the actual display and the title of the rss feeds showing up, but i can't plug in the rss feed link without getting an error. this is the code i am using (there is a bit more to the code, but this is the only place the problem is showing up):


<?php include('RSS/rss_fetch.inc');

$rss = fetch_rss('rss feed link goes here');
// array shows first 8 results
$items = array_slice($rss->items, 0, 8);
// Cycle through each item and echo
foreach ($items as $item )

{ ?>


the bolded line is the only place i'm running into a problem. i have the correct rss feed link stored in the database. i would reference it in my code as
<?php echo $row_resourceFeed_rs['rssLink']; ?>

however, if i replace the current rss link (the one bolded above) with the php call to the database for the correct link, i get an error. can somebody please tell me how to pull the rss feed link into that bolded line?

Re: need help setting a php variable

Posted: Mon Jun 06, 2011 10:41 pm
by superdezign
  1. What is the error you are getting?
  2. Where is fetch_rss() defined?
  3. Use

    Code: Select all

     tags ;)[/list]

Re: need help setting a php variable

Posted: Tue Jun 07, 2011 3:50 pm
by mathruD
the error message is:
Parse error: syntax error, unexpected T_STRING in /home2/thesile4/public_html/resources2.php on line 123

(line 123 is the second line in the code below. i get the error as soon as i place in the call to the database for the rss feed link. it's not properly reading the php call. it's showing up as blue in the code snippet, whereas all other php calls are black.)

here is the code again (sorry about not using code tags before. i wasn't sure how to do that.

Code: Select all

 <?php include('RSS/rss_fetch.inc');
$rss = fetch_rss('<?php echo $row_resourceFeed_rs['resource_rssLink']; ?>');
// Split the array to show first 5
$items = array_slice($rss->items, 0, 8);
// Cycle through each item and echo
foreach ($items as $item )
{  ?>
      
<li><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></li>
<?php } ?>
fetch_rss() is defined in the fetch_rss.inc file, which is nested within a folder called RSS. it's all from a tutorial i found for displaying rss feeds, as i've never worked with them before. i was just trying to use php with the code.

Re: need help setting a php variable

Posted: Tue Jun 07, 2011 3:57 pm
by AbraCadaver
The error is because you have unescaped single-quotes inside a single-quoted string. But why are you using PHP code and echoing there? Just do:

Code: Select all

$rss = fetch_rss($row_resourceFeed_rs['resource_rssLink']);

Re: need help setting a php variable

Posted: Tue Jun 07, 2011 5:51 pm
by mathruD
that worked perfectly. i don't know why i was using the php code there. i completely overlooked the fact that since i was already in a php block that i didn't have to use the php code again. i'm still learning some of this stuff.

thanks a lot for the help.