0

I am using the attached script to output 100 results at a time from an XML file. The total record count e.g 1000 is held in $totalRecordCount = $oXML['total_record_count']; The user enters a search term in a form and results get outputted on same page. Each result is a link to a detail page. How do I integrate pagination in it if there's a 1000 results 1|2|3...10? I tried integrating something as per Simple pagination for foreach loop with no success however. Any help appreciated. Thanks

<?php

if (isset($_GET['submit2'])) {
    $search2 = preg_replace('/\s+/', '+', $_GET["dept-keywords"]);
    $sanitizeSearch2 = filter_var($search2, FILTER_SANITIZE_STRING);
    echo '<b>Results: ' . $_GET["dept-keywords"] . '</b>';
    $ch = curl_init();
    $baseUrl = 'https://example.com/';
    $templateParamNames = array('{user_id}');
    $templateParamValues = array(urlencode('exl_impl'));
    $baseUrl = str_replace($templateParamNames, $templateParamValues, $baseUrl);
    $queryParams = array(
        //info

    );
    $url = $baseUrl . "?" . http_build_query($queryParams);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    $oXML = new SimpleXMLElement($response);
    echo '<ol>';
    $totalRecordCount = $oXML['total_record_count'];
    $count = 0;
    foreach ($oXML->user as $user) {
        $first_name = $user->first_name;
        $user_link = strtolower("https://example.com/" . $first_name);
        echo '<li>';
        echo "<a href='" . $user_link . "'> " . $first_name . " </a>" . "\r\n";
        echo '</li>';
        $count++;
    }
    if ($count == 0) {
        echo '<label>Sorry, no results!</label>';
    }
    echo '</ol>';
    curl_close($ch);
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
User301276
  • 55
  • 1
  • 8
  • Please don't give us statements such as _" tried integrating something as per [...] with no success however"_, that is absolutely not helpful. We can not possibly know what you might have done wrong. _Show us_ what exactly you tried, and give a proper problem description along with it. – CBroe Oct 06 '21 at 13:09
  • 2
    **[You should not switch off `CURLOPT_SSL_VERIFYHOST` or `CURLOPT_SSL_VERIFYPEER`](https://paragonie.com/blog/2017/10/certainty-automated-cacert-pem-management-for-php-software)**. It could be a security risk! [Here is how to get the certificate bundle if your server is missing one](https://stackoverflow.com/a/32095378/1839439) – Dharman Oct 07 '21 at 12:15
  • 2
    Constant [FILTER_SANITIZE_STRING](https://stackoverflow.com/questions/69207368/constant-filter-sanitize-string-is-deprecated) is deprecated. Please stop using it. – Dharman Oct 07 '21 at 12:15

0 Answers0