modifiedcontent Posted January 2, 2008 Share Posted January 2, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/ Share on other sites More sharing options...
Barand Posted January 2, 2008 Share Posted January 2, 2008 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/#findComment-428433 Share on other sites More sharing options...
modifiedcontent Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks for the suggestion Barand. I doesn't work unfortunately. No error messages, just an empty page, with or without removing the pointless $id = 'id'; etc. I had at the top. Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/#findComment-428452 Share on other sites More sharing options...
Barand Posted January 2, 2008 Share Posted January 2, 2008 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 />'; } Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/#findComment-428523 Share on other sites More sharing options...
ohdang888 Posted January 2, 2008 Share Posted January 2, 2008 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/#findComment-428530 Share on other sites More sharing options...
modifiedcontent Posted January 2, 2008 Author Share Posted January 2, 2008 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. ??? Quote Link to comment https://forums.phpfreaks.com/topic/84151-keep-associated-results-from-mysql-together/#findComment-428631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.