Jump to content

pagination xml arrays help


legends

Recommended Posts

i have been trying to figure out how to paginate an array and am not getting the results that i thought i would.  i am trying to get the pagination by array $rss_feeds[publish_date] as there i a number that to sort by.  there are 6 total pieces of information that are also set into arrays as well that i need to load but am just no getting the pagination to work at all.

 

          $rss_feeds[title][] = $rss_title;

          $rss_feeds[summary][] = $rss_summary;

  $rss_feeds[newssourceurl][] = $rss_newssourceurl;

  $rss_feeds[newssource][] = $rss_newssource;

  $rss_feeds[publish_date][] = $rss_publish_date;

          $rss_feeds[clickurl][] = $rss_clickurl;

 

 

Here is the results set that i use, any help with this would be greatly appreciated

 

  function display_result()

  {

      global $rss_feeds;

      rsort ($rss_feeds[publish_date]);

      // Number Of Items @page

      $num_result = count($rss_feeds[publish_date]);

      $num_item = ITEM_PER_PAGE;

      if ($num_result < $num_item) {

          $num_item = $num_result;

      }

 

      // Display

  echo '<div class="news_result">' . PHP_EOL;

      for ($x = 0; $x < $num_item; $x++) {

      echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">' . PHP_EOL;

      echo '  <tr>' . PHP_EOL;

      echo '    <td>' . PHP_EOL;

      echo '<table cellpadding="0" cellspacing="2" border="0" width="100%">' . PHP_EOL;

      echo '  <tr>' . PHP_EOL;

      echo '    <td valign="top">' . PHP_EOL;

      echo '      <a href="'. $rss_feeds['clickurl'][$x] .'" target="_blank">' . $rss_feeds['title'][$x] . '</a>' . PHP_EOL;

      echo '    </td>' . PHP_EOL;

      echo '  </tr>' . PHP_EOL;

      echo '  <tr>' . PHP_EOL;

      echo '    <td valign="top">' . PHP_EOL;

      echo '      <p>' . $rss_feeds['summary'][$x] . '</p>' . PHP_EOL;

      echo '    </td>' . PHP_EOL;

      echo '  </tr>' . PHP_EOL;

      echo '  <tr>' . PHP_EOL;

      echo '    <td valign="top">' . PHP_EOL;

      echo '      <p><font color="green">' . str_replace("http://", "", $rss_feeds['newssourceurl'][$x]) . '</font>  -  ' . $rss_feeds['newssource'][$x] . '  -  <font color="gray">' .  date("M jS, Y - g:i:s a",$rss_feeds['publish_date'][$x]) . '</font>  </p>' . PHP_EOL;

      echo '    </td>' . PHP_EOL;

      echo '  </tr>' . PHP_EOL;

      echo '    </td>' . PHP_EOL;

      echo '  </tr>' . PHP_EOL;

      echo '</table>' . PHP_EOL;

      }

      echo '</div>' . PHP_EOL;

 

      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);

          // NewsSourceUrl

          $rss_newssourceurl = cleanup_result($item->NewsSourceUrl);

          // NewsSource

          $rss_newssource = cleanup_result($item->NewsSource);

          $rss_newssource = ucwords($rss_newssource);

          // ModificationDate

          $rss_publish_date = cleanup_result($item->PublishDate);

          $rss_publish_date = ucwords($rss_publish_date);

          // ClickUrl

          $rss_clickurl = cleanup_result($item->ClickUrl);

          // RSS Feeds

          $rss_feeds[title][] = $rss_title;

          $rss_feeds[summary][] = $rss_summary;

  $rss_feeds[newssourceurl][] = $rss_newssourceurl;

  $rss_feeds[newssource][] = $rss_newssource;

  $rss_feeds[publish_date][] = $rss_publish_date;

          $rss_feeds[clickurl][] = $rss_clickurl;

      }

      return $rss_feeds;

  }

Link to comment
https://forums.phpfreaks.com/topic/192687-pagination-xml-arrays-help/
Share on other sites

this is what i have found to do this pagination but i am new to this and dont know where to start with implementing this code into the page to paginate

 

  // the script name;

 

$webpage = basename($_SERVER['PHP_SELF']);

 

 

 

function pagination_one($total_pages,$page){

 

    global $webpage;

   

        //start_to build the $pagination

   

    $pagination='<div class="page_numbers">

                    <ul>';

     

        //if there are more than one page of results

     

    if($total_pages!=1){

   

            //loop up to the total_pages of results

   

        for ($i=1;$i<$total_pages+1;$i++){

       

                //if the current page no link

       

            if($i==$page){

                $pagination.='<li><a class="current">'.$i.'</a></li>

                ';

            }

           

                //else provide a link

           

            else{

                $pagination.='<li><a href="'.$webpage.'?page='.$i.'">'.$i.'</a></li>

                ';

            }

        }

       

    }

   

        //if one page of results

   

    else{

        $pagination.='<li><a href="" class="current">1</a></li>';

    }

   

        //finish and return

   

    $pagination.='</ul>

            </div>';

           

    return($pagination);

}

 

 

 

ok i got the pagination issue resolved with just one thing that has me puzzled, if i have 50 results and show 15 per page that leaves the 4th page with results less than 15 and im trying to figure out how to stop the loop on if there are not enough results to fill the page.

 

Here is the pagination that i have come up with.

 

  function display_result()
  {
      global $rss_feeds, $argv;
  rsort ($rss_feeds[publishdate]);
  $searchresultreplace = array(".htm", "_");
  $searchresult = str_replace($searchresultreplace, " ", $_GET["query"]);
  $webpagereplace = array(" ");
  $webpage = str_replace($webpagereplace, "+", $_GET["query"]);
       // Number Of Items @page
      $num_result = count($rss_feeds[publishdate]);
      $num_item = ITEM_PER_PAGE;
      if ($num_result < $num_item) {
          $num_item = $num_result;
      }

    // Load you results into the array with numerical keys
    $contents = Array($rss_feeds[publishdate],$rss_feeds[title],$rss_feeds[summary],$rss_feeds[newssourceurl],$rss_feeds[newssource],$rss_feeds[clickurl]);
    // How many items per page?
    $per = 20;
    // Count Number of pages and round up
    $numPages = ceil(($num_result/$per));

    // This next check finds out what page we have selected, if not we say page 1
    if (!isset($_GET["page"]))
    {
        $st = 1;
    }
    else
    {
        $st = $_GET["page"];
    }

    // Find the starting key of the page we are on
    $currentStart = ($st*$per)-$per;

    // Now we print out the content of the array between the starting key and the starting key of the next page
  echo '	  <p><b>' . $num_result . ' results found for ' . $searchresult . '</b></p>' . PHP_EOL;
          echo '	  <img src="' . SCRIPT_DIR . RESOURCES_PATH . '/pixel.gif" height="2">' . PHP_EOL;
  echo '<div class="newsburner_result">' . PHP_EOL;
      for ( $x = $currentStart; $x <= (($currentStart+$per)-1); $x += 1)
      {
      echo '<table id="newsburner_result" cellpadding="0" cellspacing="0" border="0" width="100%">' . PHP_EOL;
      echo '  <tr>' . PHP_EOL;
      echo '    <td>' . PHP_EOL;
      echo '	  <img src="' . SCRIPT_DIR . RESOURCES_PATH . '/pixel.gif" height="3">' . PHP_EOL;
      echo '<table cellpadding="0" cellspacing="2" border="0" width="100%">' . PHP_EOL;
      echo '  <tr>' . PHP_EOL;
      echo '    <td valign="top">' . PHP_EOL;
      echo '      <a href="'. $rss_feeds['clickurl'][$x] .'" target="_blank">' . $rss_feeds['title'][$x] . '</a>' . PHP_EOL;
      echo '    </td>' . PHP_EOL;
      echo '  </tr>' . PHP_EOL;
      echo '  <tr>' . PHP_EOL;
      echo '    <td valign="top">' . PHP_EOL;
      echo '      <p>' . $rss_feeds['summary'][$x] . '</p>' . PHP_EOL;
      echo '    </td>' . PHP_EOL;
      echo '  </tr>' . PHP_EOL;
      echo '  <tr>' . PHP_EOL;
      echo '    <td valign="top">' . PHP_EOL;
      echo '      <p><font color="green">' . str_replace("http://", "", $rss_feeds['newssourceurl'][$x]) . '</font>  -  ' . $rss_feeds['newssource'][$x] . '  -  <font color="gray">' .  date("M jS, Y - g:i:s a",$rss_feeds['publishdate'][$x]) . '</font>  </p>' . PHP_EOL;
      echo '    </td>' . PHP_EOL;
      echo '  </tr>' . PHP_EOL;
      echo '</table>' . PHP_EOL;
      echo '	  <img src="' . SCRIPT_DIR . RESOURCES_PATH . '/pixel.gif" height="3">' . PHP_EOL;
      echo '    </td>' . PHP_EOL;
      echo '  </tr>' . PHP_EOL;
      echo '</table>' . PHP_EOL;
      }
      echo '</div>' . PHP_EOL;

    // Finally display the page numbers and previous and next links
  if ( $currentStart == 0 ) {
      echo "Previous - ";
  } else {
      echo "<br /><br /><a href='search.php?query=$webpage&page=".($st-1)."'>Previous</a> - ";
  }	

    for ( $i = 1; $i <= $numPages; $i += 1)
    {
        print "<a href='search.php?query=$webpage&page=$i'>[$i]</a> ";
    }

    print "- <a href='search.php?query=$webpage&page=".($st+1)."'>Next</a>";

      return;
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.