mike2 Posted June 2, 2014 Share Posted June 2, 2014 Hello everyone. I have some code that I need some assistance with. By the way I am using CentOS 6.5 on my Linux server. Here is my current code: <html> <head></head> <body> <?php if (!isset($_POST['q'])) { ?> <img src="/wvb-logo-slogen.png" border="0" /> //code for logo <h2>Search</h2> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" /> </form> <?php } else { ?> <img src="/wvb-logo-slogen.png" border="0" /> //code for logo <h2>Search Results</h2> <?php try { // create object // $swish = new Swish('/usr/local/apache/htdocs/swish/index.swish-e'); $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from command-line $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); ?> Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'. <?php // iterate over result set // print details for each match while($r = $result->nextResult()) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; ?> </p> //Suggested Pagination code. <?php ///////////////FILLING ARRAY WITH DUMMY DATA//////////////////// $key = array(); for($i=0; $i<200; $i++) { //fill array data $key[] = "num = ".$i; } //////////////////////////////////////////////////////////////// /////////////////////START OF ARRAY PAGINATION CODE///////////////////// $ptemp="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; $pt=explode('&',$ptemp); if (strpos($ptemp,'pageno')) array_pop($pt); $pt=implode('&',$pt); $ptemp=$pt; $array=$key; // REPLACE $KEY WITH YOUR ARRAY VARIABLE $page = $_REQUEST['pageno']; $currentpage = isset($page) ? (integer)$page : 1; $numperpage = 10; //NUMBER OF RECORDS TO BE DISPLAYED PER PAGE $total = count($array); $numofpages = ceil($total / $numperpage); //TOTAL NUMBER OF PAGES if(isset($array)) { if (($currentpage > 0) && ($currentpages <= $numofpages)) { //STARTING LOOP FOR ARRAY DATA $start = ($currentpage-1) * $numperpage; for($i=$start;$i<=($numperpage+$start-1);$i++) { ///////////PLACE YOUR CODE HERE////////////////////////// echo $array[$i] .' '; //////////////////////////////////////////////////////// } } } if ($currentpage != 1) { //GOING BACK FROM PAGE 1 SHOULD NOT BET ALLOWED $previous_page = $currentpage - 1; $previous = '<a href="'.$ptemp.'?pageno='.$previous_page.'"> <</a> '; } $pages = ''; for ($a=1; $a<=$numofpages; $a++) { if ($a == $currentpage) $pages .= $a .'</u> '; else $pages .= '<a href="'.$ptemp.'?pageno='.$a.'" >'. $a .'</a> '; } $pages = substr($pages,0,-1); //REMOVING THE LAST COMMA (,) if ($currentpage != $numofpages) { //GOING AHEAD OF LAST PAGE SHOULD NOT BE ALLOWED $next_page = $currentpage + 1; $next = ' <a href="'.$ptemp.'?pageno='.$next_page.'"> ></a>'; } echo ' '. $previous . $pages . $next; //PAGINATION LINKS /////////////////////END OF ARRAY PAGINATION CODE///////////////////// ?> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html> As you can see from the code above when I implemented that code into my script I was able to get it to display but only after the </p> marker. When I did that I got the following results. Results: Found 736 match(es) for 'test'. 1 ./ITA000030192.2013.A.00.L.12.31.PDF (score: 1000) ./ITA000030192.2013.A.00.L.12.31.PDF Country: Italian Republic (Italy) Year: 2013 WVB Number: ITA000030192 Company Name: BEGHELLI num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 2 ./ITA000030164.2013.A.00.L.12.31.PDF (score: 976) ./ITA000030164.2013.A.00.L.12.31.PDF Country: Italian Republic (Italy) Year: 2013 WVB Number: ITA000030164 Company Name: CREDITO EMILIANO num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 127 ./IND000102048.2012.A.00.E.03.31.PDF (score: 457) ./IND000102048.2012.A.00.E.03.31.PDF Country: Year: 2012 WVB Number: IND000102048 Company Name: num = 0 num = 1 num = 2 num = 3 num = 4 num = 5 num = 6 num = 7 num = 8 num = 9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > 128 ./NLD000030064.2013.A.00.E.12.28.PDF (score: 457) ./NLD000030064.2013.A.00.E.12.28.PDF The results page shows that there are 736 matches. There are currently 5000 PDF files in the /var/www/html/pdf2 directory.What I am trying to accomplish in terms of pagination is twofold.First get the above page links to display on the top and bottom of the page and only display 10 results at a time on each page. Second have the links working correctly so that they can go to the correct results.Can this be accomplished with the above pagination code where it states //Suggested pagination code? Do I need to change my layout? Furthermore I was also told that I should focus on the following lines of code: <?php ///////////////FILLING ARRAY WITH DUMMY DATA//////////////////// $key = array(); for($i=0; $i<200; $i++) { //fill array data $key[] = "num = ".$i; } as well as the result variable $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); What would I need to change in these two areas in order to get what it is that I am trying to accomplish. Sorry for the large post. Any assistance would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/ Share on other sites More sharing options...
Psycho Posted June 2, 2014 Share Posted June 2, 2014 You should really look at changing how you create the logic for your pages. By intermingling PHP and HTML, it makes it very difficult to read/debug the code. Put all your 'logic' at the top of the page and create PHP variables for the different output. Then just echo the variables where needed within the HTML. I'll look through your code, but I will likely rewrite in order to better understand it. Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481644 Share on other sites More sharing options...
mac_gyver Posted June 2, 2014 Share Posted June 2, 2014 (edited) what you are asking can be accomplished, but as stated in one of your previous threads, requires that the code on your page be organized correctly (which Psycho has now also told you is needed.) also as stated in the previous thread, to paginate using an array requires that you store the result from your Swish query in that array, in a session variable (there's little point in using the array method over using the swish data seek method if you are not saving any processing time by doing it since it requires more program logic to be written for the array method.) not trying to pick on you, but do you know where in your current code you are getting the result from the Swish query so that you could modify it to use either the Swish data seek or the array method for pagination? btw - the part of the pagination code you found that is getting and modifying the url's query string parameters can all pretty much be replaced with a http_build_query() statement. Edited June 2, 2014 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481648 Share on other sites More sharing options...
Psycho Posted June 2, 2014 Share Posted June 2, 2014 (edited) Yeah, I started to try and work and that code and gave up. It's really a mess. Break down specific operations that need to occur and create functions instead of doing everything in-line. I would create, at a minimum, a function that takes parameters for the query string, the start position and the count. That function should return an array of the search results for the page. Then have another function to create the output for results. You could then easily implement paging functionality. EDIT: Also, if you are going to implement paging you should also set a sort order using setSort Edited June 2, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481653 Share on other sites More sharing options...
mac_gyver Posted June 2, 2014 Share Posted June 2, 2014 (edited) this is code (untested since i don't have any swish code) based on your previous thread, using the swish data seek method, hopefully you can learn from this - <?php // business logic - determine what to do on the page and get/produce the data that's needed for the content on the page $limit = 10; // pagination number of rows per page // get any search term (required) $search_term = isset($_GET['q']) ? trim($_GET['q']) : ''; if($search_term != ''){ try { $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from url query string $result = $swish->query($search_term); // at this point, you know how many matches there are and can calculate the number of pages // Find out how many items are in the table $totalItems = $result->hits; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $page = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query/result set $offset = ($page - 1) * $limit; $data = array(); if($totalItems > 0){ // at least one result // the calculated $offset is used in the following to seek to the correct starting row $result->seekResult($offset); $x = 1; // loop until no more rows or $limit has been reached while(($r = $result->nextResult()) && $x <= $limit) { $data[] = $r; $x++; } // get company/country information (only if there are results to display) $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); } } catch (SwishException $e) { trigger_error($e->getMessage()); die('Sorry, the application experienced an error and cannot run.'); } } // presentation logic - take the data produced by the business logic above and output the html document // build pagination here... $pagination_links = ''; if(isset($totalPages) && $totalPages > 1){ // more than one page // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $totalItems); // "back" link if($page > 1){ $_GET['page'] = 1; $qs = http_build_query($_GET, '', '&'); $prevlink = "<a href='?$qs' title='First page'>«</a>"; $_GET['page'] = $page - 1; $qs = http_build_query($_GET, '', '&'); $prevlink .= " <a href='?$qs' title='Previous page'>‹</a>"; } else { $prevlink = '<span class="disabled">«</span> <span class="disabled">‹</span>'; } // "forward" link if($page < $totalPages){ $_GET['page'] = $page + 1; $qs = http_build_query($_GET, '', '&'); $nextlink = "<a href='?$qs' title='Next page'>›</a>"; $_GET['page'] = $totalPages; $qs = http_build_query($_GET, '', '&'); $nextlink .= " <a href='?$qs' title='Last page'>»</a>"; } else { $nextlink = '<span class="disabled">›</span> <span class="disabled">»</span>'; } $pagination_links = "<div id='paging'><p>$prevlink Page $page of $totalPages pages, displaying $start-$end of $totalItems results $nextlink</p></div>"; } ?> <html> <head></head> <body> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="get" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" value="<?php echo htmlentities($search_term); ?>" /> <input type='submit' value='Submit'> </form> <?php if($search_term != ''){ ?> <h2>Search Results</h2> Found <?php echo $totalItems; ?> match(es) for '<?php echo htmlentities($search_term); ?>'. <?php echo "<div>$pagination_links</div>"; // display pagination at the top of data // iterate over result set foreach($data as $r) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; echo '</p>'; } // end of data display loop echo "<div>$pagination_links</div>"; // display pagination at the bottom of data } // end search results ?> </body> </html> btw - again not trying to pick on you, but are you testing your current code? what happens after you preform one search (or your search doesn't match anything)? you are not redisplaying the search form, so the visitor doesn't have any direct way of searching again. in the above code, the display of the search form is unconditional. Edited June 2, 2014 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481655 Share on other sites More sharing options...
mike2 Posted June 2, 2014 Author Share Posted June 2, 2014 this is code (untested since i don't have any swish code) based on your previous thread, using the swish data seek method, hopefully you can learn from this - <?php // business logic - determine what to do on the page and get/produce the data that's needed for the content on the page $limit = 10; // pagination number of rows per page // get any search term (required) $search_term = isset($_GET['q']) ? trim($_GET['q']) : ''; if($search_term != ''){ try { $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from url query string $result = $swish->query($search_term); // at this point, you know how many matches there are and can calculate the number of pages // Find out how many items are in the table $totalItems = $result->hits; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $page = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query/result set $offset = ($page - 1) * $limit; $data = array(); if($totalItems > 0){ // at least one result // the calculated $offset is used in the following to seek to the correct starting row $result->seekResult($offset); $x = 1; // loop until no more rows or $limit has been reached while(($r = $result->nextResult()) && $x <= $limit) { $data[] = $r; $x++; } // get company/country information (only if there are results to display) $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); } } catch (SwishException $e) { trigger_error($e->getMessage()); die('Sorry, the application experienced an error and cannot run.'); } } // presentation logic - take the data produced by the business logic above and output the html document // build pagination here... $pagination_links = ''; if(isset($totalPages) && $totalPages > 1){ // more than one page // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $totalItems); // "back" link if($page > 1){ $_GET['page'] = 1; $qs = http_build_query($_GET, '', '&'); $prevlink = "<a href='?$qs' title='First page'>«</a>"; $_GET['page'] = $page - 1; $qs = http_build_query($_GET, '', '&'); $prevlink .= " <a href='?$qs' title='Previous page'>‹</a>"; } else { $prevlink = '<span class="disabled">«</span> <span class="disabled">‹</span>'; } // "forward" link if($page < $totalPages){ $_GET['page'] = $page + 1; $qs = http_build_query($_GET, '', '&'); $nextlink = "<a href='?$qs' title='Next page'>›</a>"; $_GET['page'] = $totalPages; $qs = http_build_query($_GET, '', '&'); $nextlink .= " <a href='?$qs' title='Last page'>»</a>"; } else { $nextlink = '<span class="disabled">›</span> <span class="disabled">»</span>'; } $pagination_links = "<div id='paging'><p>$prevlink Page $page of $totalPages pages, displaying $start-$end of $totalItems results $nextlink</p></div>"; } ?> <html> <head></head> <body> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="get" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" value="<?php echo htmlentities($search_term); ?>" /> <input type='submit' value='Submit'> </form> <?php if($search_term != ''){ ?> <h2>Search Results</h2> Found <?php echo $totalItems; ?> match(es) for '<?php echo htmlentities($search_term); ?>'. <?php echo "<div>$pagination_links</div>"; // display pagination at the top of data // iterate over result set foreach($data as $r) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; echo '</p>'; } // end of data display loop echo "<div>$pagination_links</div>"; // display pagination at the bottom of data } // end search results ?> </body> </html> btw - again not trying to pick on you, but are you testing your current code? what happens after you preform one search (or your search doesn't match anything)? you are not redisplaying the search form, so the visitor doesn't have any direct way of searching again. in the above code, the display of the search form is unconditional. I am testing my current code. I got the results as shown above where the paginated links just keep showing up in separate results. Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481687 Share on other sites More sharing options...
mike2 Posted June 2, 2014 Author Share Posted June 2, 2014 what you are asking can be accomplished, but as stated in one of your previous threads, requires that the code on your page be organized correctly (which Psycho has now also told you is needed.) also as stated in the previous thread, to paginate using an array requires that you store the result from your Swish query in that array, in a session variable (there's little point in using the array method over using the swish data seek method if you are not saving any processing time by doing it since it requires more program logic to be written for the array method.) not trying to pick on you, but do you know where in your current code you are getting the result from the Swish query so that you could modify it to use either the Swish data seek or the array method for pagination? btw - the part of the pagination code you found that is getting and modifying the url's query string parameters can all pretty much be replaced with a http_build_query() statement. Here is my answer to your question: This is where I am getting the result from my Swish query: <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> To the best of my knowledge this code displays my PDF files as links and they open up when you click them. Is that what you are asking me? Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481692 Share on other sites More sharing options...
mike2 Posted June 2, 2014 Author Share Posted June 2, 2014 this is code (untested since i don't have any swish code) based on your previous thread, using the swish data seek method, hopefully you can learn from this - <?php // business logic - determine what to do on the page and get/produce the data that's needed for the content on the page $limit = 10; // pagination number of rows per page // get any search term (required) $search_term = isset($_GET['q']) ? trim($_GET['q']) : ''; if($search_term != ''){ try { $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from url query string $result = $swish->query($search_term); // at this point, you know how many matches there are and can calculate the number of pages // Find out how many items are in the table $totalItems = $result->hits; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $page = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query/result set $offset = ($page - 1) * $limit; $data = array(); if($totalItems > 0){ // at least one result // the calculated $offset is used in the following to seek to the correct starting row $result->seekResult($offset); $x = 1; // loop until no more rows or $limit has been reached while(($r = $result->nextResult()) && $x <= $limit) { $data[] = $r; $x++; } // get company/country information (only if there are results to display) $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); } } catch (SwishException $e) { trigger_error($e->getMessage()); die('Sorry, the application experienced an error and cannot run.'); } } // presentation logic - take the data produced by the business logic above and output the html document // build pagination here... $pagination_links = ''; if(isset($totalPages) && $totalPages > 1){ // more than one page // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $totalItems); // "back" link if($page > 1){ $_GET['page'] = 1; $qs = http_build_query($_GET, '', '&'); $prevlink = "<a href='?$qs' title='First page'>«</a>"; $_GET['page'] = $page - 1; $qs = http_build_query($_GET, '', '&'); $prevlink .= " <a href='?$qs' title='Previous page'>‹</a>"; } else { $prevlink = '<span class="disabled">«</span> <span class="disabled">‹</span>'; } // "forward" link if($page < $totalPages){ $_GET['page'] = $page + 1; $qs = http_build_query($_GET, '', '&'); $nextlink = "<a href='?$qs' title='Next page'>›</a>"; $_GET['page'] = $totalPages; $qs = http_build_query($_GET, '', '&'); $nextlink .= " <a href='?$qs' title='Last page'>»</a>"; } else { $nextlink = '<span class="disabled">›</span> <span class="disabled">»</span>'; } $pagination_links = "<div id='paging'><p>$prevlink Page $page of $totalPages pages, displaying $start-$end of $totalItems results $nextlink</p></div>"; } ?> <html> <head></head> <body> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="get" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" value="<?php echo htmlentities($search_term); ?>" /> <input type='submit' value='Submit'> </form> <?php if($search_term != ''){ ?> <h2>Search Results</h2> Found <?php echo $totalItems; ?> match(es) for '<?php echo htmlentities($search_term); ?>'. <?php echo "<div>$pagination_links</div>"; // display pagination at the top of data // iterate over result set foreach($data as $r) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (score: <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; echo '</p>'; } // end of data display loop echo "<div>$pagination_links</div>"; // display pagination at the bottom of data } // end search results ?> </body> </html> btw - again not trying to pick on you, but are you testing your current code? what happens after you preform one search (or your search doesn't match anything)? you are not redisplaying the search form, so the visitor doesn't have any direct way of searching again. in the above code, the display of the search form is unconditional. I will learn from this. Thank you for the advice. Quote Link to comment https://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/#findComment-1481694 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.