legends Posted February 7, 2010 Share Posted February 7, 2010 I have a script and am having difficulty changing the script from a shuffle to a definitive result. Right now it get the info but always shuffles the information around. Maybe it too many hours looking at the code. here is the section of the code that i need some help with i need the title, summary and clickurl to load into the $rss_feeds[0], $rss_feeds[1], $rss_feeds[2] in that order instead of always shuffling this around between the three. Any help would be greatly appreciated. // ------------------------------- // Display Result // ------------------------------- function display_result() { global $rss_feeds; shuffle($rss_feeds); // Number Of Items @page $num_result = count($rss_feeds[0]); $num_item = ITEM_PER_PAGE; if ($num_result < $num_item) { $num_item = $num_result; } // Display echo '<hr width="100%" align="left"><div id="yahoo_result">'; for ($x = 0; $x < $num_item; $x++) { echo '<p>' . $rss_feeds[0][$x] . '. ' . $rss_feeds[1][$x] . '</p><a href="'. $rss_feeds[2][$x] .'" target="_blank">Read Full Article</a><br><br><hr width="100%" align="left"><br>'; } echo '</div>'; return; } // ------------------------------- // Get Result // ------------------------------- function get_result($xml_file) { // Load XML $xml = simplexml_load_file($xml_file); foreach ($xml->Result as $item) { // Title $rss_title = cleanup_result($item->Title); $rss_title = ucwords($rss_title); // Summary $rss_summary = cleanup_result($item->Summary); $rss_summary = ucwords($rss_summary); // ClickUrl $rss_clickurl = cleanup_result($item->ClickUrl); $rss_clickurl = ucwords($rss_clickurl); // RSS Feeds $rss_feeds[title][] = $rss_title; $rss_feeds[summary][] = $rss_summary; $rss_feeds[clickurl][] = $rss_clickurl; } return $rss_feeds; } Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 7, 2010 Share Posted February 7, 2010 commenting out the shuffle() in the display_result function might help. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
legends Posted February 7, 2010 Author Share Posted February 7, 2010 no go, tried that erlier and set to sort but still wants to shuffle here is the site refresh it a few times an you will see that the link will show up in the summary after a few refreshes http://www.legends.ws Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 7, 2010 Share Posted February 7, 2010 looking at your get_results function. Your display function depends on each feed gathered from your get_results to have three parts. What would happen if one of the rss feeds only had two parts or was not in the order you expect? You must control that each part goes where wanted. HTH TEamatomic Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 It looks to me like you have a mismatch of assumptions about your array. When the array is constructed this is what it looks like: $rss_feeds[title] = array(); $rss_feeds[summary] = array(); $rss_feeds[clickurl] = array(); Then you start trying to go through the array as if the first element was numeric, which it isn't, it has the 3 keys in: 'title', 'summary', 'clickurl'. Probably what you want in get_results is to remove the 3 lines where you assign the title, summary and url to this: $rss_feeds[] = array('title' => $rss_title, 'summary' => $rss_summary, 'clickurl' => $rss_clickurl,); Shuffle is still going to make the order random, so you need to lose that. Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 Well, sorry I misread your code -- you are matched, but I'd still move to what I had, and lose the shuffle() regardless. Quote Link to comment Share on other sites More sharing options...
gizmola Posted February 7, 2010 Share Posted February 7, 2010 // ------------------------------- // Display Result // ------------------------------- function display_result() { global $rss_feeds; // Number Of Items @page $num_result = count($rss_feeds); $num_item = ITEM_PER_PAGE; if ($num_result $num_item = $num_result; } // Display echo ''; for ($x = 0; $x echo ' ' . $rss_feeds[$x]['title'] . '. ' . $rss_feeds[$x]['summary'] . 'Read Full Article '; } echo ''; return; } Quote Link to comment Share on other sites More sharing options...
legends Posted February 8, 2010 Author Share Posted February 8, 2010 ok got that figured out had to move [$x] over and all worked well as far as sorting, now it will only show 3 results. i have it config for 20 results. any ideas on what happened there? // ------------------------------- // Display Result // ------------------------------- function display_result() { global $rss_feeds; // Number Of Items @page $num_result = count($rss_feeds); $num_item = ITEM_PER_PAGE; if ($num_result < $num_item) { $num_item = $num_result; } // Display echo '<hr width="100%" align="left"><div id="yahoo_result">'; for ($x = 0; $x < $num_item; $x++) { echo '<p><b>' . $rss_feeds['title'][$x] . '</b><br>' . $rss_feeds['summary'][$x] . '</p><a href="'. $rss_feeds['clickurl'][$x] .'" target="_blank">Read Full Article</a><hr width="100%" align="left">'; } echo '</div>'; return; } // ------------------------------- // Get Result // ------------------------------- function get_result($xml_file) { // Load XML $xml = simplexml_load_file($xml_file); foreach ($xml->Result as $item) { // Title $rss_title = cleanup_result($item->Title); $rss_title = ucwords($rss_title); // Summary $rss_summary = cleanup_result($item->Summary); $rss_summary = ucwords($rss_summary); // ClickUrl $rss_clickurl = cleanup_result($item->ClickUrl); $rss_clickurl = ucwords($rss_clickurl); // RSS Feeds $rss_feeds[title][] = $rss_title; $rss_feeds[summary][] = $rss_summary; $rss_feeds[clickurl][] = $rss_clickurl; } return $rss_feeds; } Quote Link to comment Share on other sites More sharing options...
legends Posted February 8, 2010 Author Share Posted February 8, 2010 i got it, thank you for giving me some much appreciated direction on this Quote Link to comment 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.