need help setting a php variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mathruD
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 2:58 am

need help setting a php variable

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: need help setting a php variable

Post by superdezign »

  1. What is the error you are getting?
  2. Where is fetch_rss() defined?
  3. Use

    Code: Select all

     tags ;)[/list]
mathruD
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 2:58 am

Re: need help setting a php variable

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: need help setting a php variable

Post 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']);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mathruD
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 2:58 am

Re: need help setting a php variable

Post 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.
Post Reply