Jump to content

Recommended Posts

I have this code to take RSS feeds from a database and output them via SimplePie. It works great, but I have trouble showing the id, username etc. associated with the feeds. This obviously doesn't work:

$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$id = 'id';
$firstname = 'firstname';
$username = 'username';

$feeds = array();
while ($cur_feed = mysql_fetch_assoc($result))
    $feeds[] = $cur_feed['rssfeed'];

// This array will hold the items we'll be grabbing.
$first_items = array();

// Let's go through the array, feed by feed, and store the items we want.
foreach ($feeds as $url)
{
    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();

...
<p class="footnote"><a href="member.php?id=<?php echo $id; ?>" title="<?php echo $firstname.'\'s Member Page'; ?>"><?php echo $username; ?></a> | <a href="<?php echo $feed->get_permalink(); ?>" target="_blank"><?php echo $feed->get_title(); ?></a> | <?php echo $item->get_date('M j, Y | g:i a'); ?></p><br />

What should I use instead of $id=... etc. to show the correct data with the feed results?

 

It's probably simple, I think I've done something similar before, but I can't find it...

try

<?php
$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$id = 'id';
$firstname = 'firstname';
$username = 'username';

$feeds = array();
while ($cur_feed = mysql_fetch_row($result))
    $feeds[] = $cur_feed;

// This array will hold the items we'll be grabbing.
$first_items = array();

// Let's go through the array, feed by feed, and store the items we want.
foreach ($feeds as $row)
{
    list ($id, $firstname, $username, $url) = $row;
    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();

echo <<<TEXT
<p class="footnote"><a href="member.php?id=<?php echo $id; ?>" title="<?php echo $firstname.'\'s Member Page'; ?>"><?php echo $username; ?></a> | <a href="<?php echo $feed->get_permalink(); ?>" target="_blank"><?php echo $feed->get_title(); ?></a> | <?php echo $item->get_date('M j, Y | g:i a'); ?></p><br />
TEXT;
}
?>

try this revised section

<?php
foreach ($feeds as $row)
{
    list ($id, $firstname, $username, $url) = $row;
    // Use the long syntax
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->init();
    $link = $feed->get_permalink();
    $title = $feed->get_title();
echo '
<p class="footnote"><a href="member.php?id=$id" title="$firstname\'s Member Page">$username</a> | <a href="$link" target="_blank">$title</a> | '. $item->get_date('M j, Y | g:i a').'</p><br />';

}

idk if this will help a lot....

but i do a similar thing and it works perfectly

 

<?php

mysql_connect("localhost", "--", "-----") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$new_games = mysql_query("SELECT link, game_picture_url, type, counter FROM game ORDER BY counter LIMIT 10")
or die(mysql_error());  

while($row = mysql_fetch_assoc($new_games)){       
   echo '<td>';
   echo'<center>';
   echo '<font size=3>';
   echo '<img src="gamepic/';
   echo $row['game_picture_url'];
   echo '" height="120" width="120"><br>';
   echo $row['link'].'<br>';
   echo '<font size=2>';
   echo '(';
   echo $row['type'];
   echo ')';
   echo '</td>';
}


?>

The latest two suggestions don't work. Thanks though. :)

 

The problem with ohdang888's solution is that I already have this line in my code:

while ($cur_feed = mysql_fetch_assoc($result))

 

I've tried including id, username etc. somewhere under that line, but couldn't get it to work. Simply adding ohdang888's solution apparently causes conflicts.

 

I've tried several variations of Barand's solution, without luck. I don't have to define $link and $title. SimplePie handles that. I only need to figure out how to connect the other database results to their feed.

 

The closest I've come to a result is with this:

$query="SELECT id, firstname, username, rssfeed FROM members WHERE rssfeed!=''";
$result=mysql_query($query);

$feeds = array();
while ($cur_feed = mysql_fetch_assoc($result))
    $feeds[] = $cur_feed['rssfeed'];
$id = mysql_result($result,$cur_feed,"id");
$firstname = mysql_result($result,$cur_feed,"firstname");
$username = mysql_result($result,$cur_feed,"username");

But it attaches the user data of the first feed to all posts/feeds.  ???

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.