topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 11:00 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Building Pagination With Php 7 Using Mysqli And Prepared Statements  (Read 8769 times)

The Code Queryer

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 33
    • View Profile
    • Donate to Member
Php Folks,

I am trying to create a php script that queries my mysql database and shows results using pagination.
Here are my requirements:

REQUIREMENTS
* Language: Php
* Php Version: 7
* Programming Style: Procedural
* Php Extension: Mysqli
* Sql Injection Prevention Method: Prepared Statements

* Web Form Design: Html 5 Compatible/Compliant
* Search Feature - Exact Match & Fuzzy Match Options (Search Usernames - See attached file for mysql tbl columns)
* Pagination - Max Results (rows) per page: 25
* Page Design: Responsive Web Design using Html 5 & CSS (latest)

I have been googling for months now and found no tutorials based on my requirements.
Tutorial are either in Pdo (Oop Style) and do not use Mysqli extension.
Or tutorials are in Procedural Style but DO NOT use Prepared Statements.
Or, tutorials are in Procedural Style and DO use Prepared Statements but do not have the SEARCH function. No EXACT MATCH or FUZZY SEARCH features exist.
None of them are Responsive Web Design suitable for both computer users and mobile phone users.

For our newbies' learning purposes. Can anyone be kind enough to show a mini pagination script ?
You may leave-out the following as I am likely to manage this with Bootsrap design tutorials:
* Page Design: Responsive Web Design using Html 5 & CSS (latest).

Thank You

NOTE: Attached file will show you what my mysql table looks like.


« Last Edit: April 08, 2019, 04:58 PM by The Code Queryer »

The Code Queryer

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 33
    • View Profile
    • Donate to Member
Php Folks,

The following code meets all my REQUIREMENTS mentioned on my original post with 2 exceptions:

* Search feature - EXACT MATCH & FUZZY SEARCH
* Web Responsive Design


This code of mine works fine. It PRACTICALLY displays all results (rows) from the mysql table.


<?php 
//https&#58;//www.w3schools.com/whatis/tryit.asp?filename=trywhatis_bootstrap_table&stacked=h
//Required PHP Files. 
include 'header_account.php'//Required on all webpages of the Account. 
?>


<?php 
if (!$conn

$error mysqli_connect_error(); 
$errno mysqli_connect_errno(); 
print "$errno&#58; $error\n"
exit(); 


// Get the total number of records from our table "students". 
$total_pages $conn->query('SELECT * FROM browsing_histories')->num_rows

// Check if the page number is specified and check if it's a number, if not return the default page number which is 1. 
$page_number = isset($_GET['page_number'&#93;) && is_numeric($_GET['page_number'&#93;) ? $_GET['page_number'&#93; &#58; 1; 
//Number of results to show on each page. 
$num_results_on_page 25

if (
$stmt_1 $conn->prepare('SELECT * FROM browsing_histories ORDER BY id LIMIT ?,?')) { 
// Calculate the page to get the results we need from our table. 
$calc_page = ($page_number 1) * $num_results_on_page
$stmt_1->bind_param('ii'$calc_page$num_results_on_page); 
$stmt_1->execute(); 
//Get the results...
$result $stmt_1->get_result();  //Do not make this into $result_1 as there is only 1 $result on this page. 

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_http $_SERVER['HTTP_REFERER'&#93;; //This fails to capture the Query String! 

if(!empty($_SERVER['QUERY_STRING'&#93;)) 

$query_string $_SERVER['QUERY_STRING'&#93;; 

//$referral_page = "$referral_page_http?$query_string"; //Added the Query String. 
$referral_page "$referral_page_http"//No Query String. 

$referral_page_original "$referral_page"//Query String included in Url. 
$referral_page_to_convert "$referral_page_original"//Query String included in Url. 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http?$query_string"//Added the Query String. Added the query string to add the proxied url onto my proxy's url. So now, the url includes both proxy's url and the proxied url. Eg. http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 
//$current_page = "$current_page_http"; //No Query String. 

$current_page_original "$current_page"//Query String included in Url. Url includes proxy's url and proxied url. 
$current_page_non_proxied "$query_string"//Url only includes proxied url's actual url. Excludes the proxy's url. 
$current_page_to_convert "$current_page_non_proxied"//Convert only the proxied url's actual url. And not the proxy's url. 

else 

$referral_page "$referral_page_http"//Added NO Query String. 
$referral_page_original "$referral_page"//Query String NOT included in Url. 
$referral_page_to_convert "$referral_page_original"//Query String NOT included in Url. 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http"//Url only includes my proxy's url. Eg. http&#58;//www.proxy.com/proxify_url? and not http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 

$current_page_original "$current_page"//Query String NOT included in Url. Url includes proxy's url and NOT the proxied url. 
$current_page_to_convert "$current_page"//Converting only the proxy's actual url. And not the proxied url as it NOT exists in the url. 


else 

if(!empty($_SERVER['QUERY_STRING'&#93;)) 

$query_string $_SERVER['QUERY_STRING'&#93;; 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
//$current_page = "$current_page_http?$query_string"; //Added the Query String. Added the query string to add the proxied url onto my proxy's url. So now, the url includes both proxy's url and the proxied url. Eg. http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 
$current_page "$current_page_http"//No Query String. 

$current_page_original "$current_page"//Query String included in Url. Url includes proxy's url and proxied url. 
$current_page_non_proxied "$query_string"//Url only includes proxied url's actual url. Excludes the proxy's url. 
$current_page_to_convert "$current_page_non_proxied"//Convert only the proxied url's actual url. And not the proxy's url. 

else 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http"//Url only includes my proxy's url. Eg. http&#58;//www.proxy.com/proxify_url? and not http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 

$current_page_original "$current_page"//Query String NOT included in Url. Url includes proxy's url and NOT the proxied url. 
$current_page_to_convert "$current_page"//Converting only the proxy's actual url. And not the proxied url as it NOT exists in the url. 



if(empty(
$visiting_pages_count)) 

$visiting_pages_count "1"

else 

$visiting_pages_count++; 


if(
$visiting_pages_count == "1"

$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"
if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "2"

$current_page_converted "$settings_admin_second_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_second_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "3"

$current_page_converted "$settings_user_third_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_third_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "4"

$current_page_converted "$settings_admin_fourth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_fourth_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "5"

$current_page_converted "$settings_user_fifth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_fifth_quick_link"."$referral_page_to_convert"

}  
elseif(
$visiting_pages_count == "6"

$current_page_converted "$settings_admin_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_first_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "7"

$current_page_converted "$settings_user_second_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_second_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "8"

$current_page_converted "$settings_admin_third_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_third_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "9"

$current_page_converted "$settings_user_fourth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_fourth_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "10"

$current_page_converted "$settings_admin_fifth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_fifth_quick_link"."$referral_page_to_convert"

}  
elseif(
$visiting_pages_count "1")  

$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"


else 

$visiting_pages_count "1"
$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"



$followed_page_original "$current_page_original"
$followed_page_converted "$current_page_converted"

$follower_username $user
$follower_browser $_SERVER['HTTP_USER_AGENT'&#93;; 

//Insert the User's Click Logs into Mysql Database using Php's Sql Injection Prevention Method "Prepared Statements". 
//All entries related to the "Follower" apart from "followee_username" and "followee_browsed_page_converted". 
$stmt_2 mysqli_prepare($conn,"INSERT INTO trailing_histories(query_type,followed_word,query_string,followed_page_original,followed_page_non_proxied,followed_page_converted,referral_page_original,referral_page_non_proxied,referral_page_converted,followee_username,username,gender,age_range,date_of_birth,skin_complexion,height,weight,sexual_orientation,religion,education,profession,marital_status,working_status,country_of_birth,home_town,home_neighbourhood,home_borough,home_council,home_city,home_county,home_district,home_region,home_state,home_country) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 
mysqli_stmt_bind_param($stmt_2,'sssssssssssssiisssssssssssssssssss',$query_type,$followed_word,$query_string,$followed_page_original,$followed_page_non_proxied,$followed_page_converted,$referral_page_original,$referral_page_non_proxied,$referral_page_converted,$followee_username,$username,$gender,$age_range,$date_of_birth,$skin_complexion,$height,$weight,$sexual_orientation,$religion,$education,$profession,$marital_status,$working_status,$country_of_birth,$home_town,$home_neighbourhood,$home_borough,$home_council,$home_city,$home_county,$home_district,$home_region,$home_state,$home_country); 
mysqli_stmt_execute($stmt_2); 

//Check if User's Click Logs have been successfully submitted or not. 
if (!$stmt_2

die("<h3 style='text-align&#58;center'> 
ERROR 1&#58; Sorry! Our system is currently experiencing a problem logging your trailing!<br> 
SUGGESTION&#58; Try visiting this page another time.</h3>"
); 

else 

mysqli_stmt_close($stmt_2);

?>


<!DOCTYPE html>
<html>
<head>
<title><?php echo "Browsing History in $server_time Time.";?></title>
<meta content="text/html; charset=ISO-8859-1" http-equiv=" content-type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html {
font-family; Tahoma, Geneva, sans-serif;
padding: 20px;
background-color: #F8F9F9;
}
table {
border-collapse: collapse;
width: 500px;
}
td, th {
padding: 10px;
}
th {
background-color: #54585d;
color: #ffffff;
font-weight: bold;
font-size: 13px;
border: 1px solid #54585d;
}
td {
color: #636363;
border: 1px solid #dddfe1;
}
tr {
background-color: #f9fafb;
}
tr:nth-child(odd) {
background-color: #ffffff;
}
.pagination {
list-style-type: none;
padding: 10px 0;
display: inline-flex;
justify-content: space-between;
box-sizing: border-box;
}
.pagination li {
box-sizing: border-box;
padding-right: 10px;
}
.pagination li a {
box-sizing: border-box;
background-color: #e2e6e6;
padding: 8px;
text-decoration: none;
font-size: 12px;
font-weight: bold;
color: #616872;
border-radius: 4px;
}
.pagination li a:hover {
background-color: #d4dada;
}
.pagination .next a, .pagination .prev a {
text-transform: uppercase;
font-size: 12px;
}
.pagination .currentpage a {
background-color: #518acb;
color: #fff;
}
.pagination .currentpage a:hover {
background-color: #518acb;
}
</style>
</head>
<body>
<p align="center"><span style="font-weight:bold;"><?php echo "Search Result for&#58;<br> \"All Users\""?></span></p>
<br>
<br>
<table>
<tr>
<th>Submission Number</th>
<th>Date & Time</th>
<th>Query Type</th>
<th>Followed Word</th>
<th>Query String</th>
<th>Browsed Page Original</th>
<th>Browsed Page Non-Proxied</th>
<th>Browsed Page Converted</th>
<th>Referral Page Original</th>
<th>Referral Page Non-Proxied</th>
<th>Referral Page Converted</th>
<th>Username</th>
<th>Gender</th>
<th>Age Range</th>
<th>Date Of Birth</th>
<th>Skin Complexion</th>
<th>Height</th>
<th>Weight</th>
<th>Sexual Orientation</th>
<th>Religion</th>
<th>Education</th>
<th>Profession</th>
<th>Marital Status</th>
<th>Working Status</th>
<th>Country Of Birth</th>
<th>Home Town</th>
<th>Home Neighbourhood</th>
<th>Home Borough</th>
<th>Home Council</th>
<th>Home City</th>
<th>Home County</th>
<th>Home District</th>
<th>Home Region</th>
<th>Home State</th>
<th>Home Country</th>
</tr>
<?php while ($row $result->fetch_assoc())&#58; ?>
<tr>
<td><?php echo $row['id'&#93;; ?></td>
<td><?php echo $row['date_and_time'&#93;; ?></td>
<td><?php echo $row['query_type'&#93;; ?></td>
<td><?php echo $row['followed_word'&#93;; ?></td>
<td><?php echo $row['query_string'&#93;; ?></td>
<?php //Browsed Page Original contains both Proxy's Url and Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_original&browsed_page_original=<?php echo $row['browsed_page_original'&#93;; ?>"><?php echo $row['browsed_page_original'&#93;; ?></a></td>
<?php //Browsed Page Non-Proxied contains Direct Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_non_proxied&browsed_page_non_proxied=<?php echo $row['browsed_page_non_proxied'&#93;; ?>"><?php echo $row['browsed_page_non_proxied'&#93;; ?></a></td>
<?php //Browsed Page Converted contains only Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_converted&browsed_page_converted=<?php echo $row['browsed_page_converted'&#93;; ?>"><?php echo $row['browsed_page_converted'&#93;; ?></a></td>
<?php //Referral Page Original contains only Proxied Url. And so preceding the Proxy's Url onto the url from the followee_browser.php page. Check that page's source code. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_original&referral_page_original=<?php echo $row['referral_page_original'&#93;; ?>"><?php echo $row['referral_page_original'&#93;; ?></a></td>
<?php //Browsed Page Non-Proxied contains Direct Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_non_proxied&browsed_page_non_proxied=<?php echo $row['referral_page_non_proxied'&#93;; ?>"><?php echo $row['referral_page_non_proxied'&#93;; ?></a></td>
<?php //Referral Page contains only Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_converted&referral_page_converted=<?php echo $row['referral_page_converted'&#93;; ?>"><?php echo $row['referral_page_converted'&#93;; ?></a></td>
<td><a href="profile.php?followee_username=<?php echo $row['username'&#93;; ?>"><?php echo $row['username'&#93;; ?></a></td>
<td><?php echo $row['gender'&#93;; ?></td>
<td><?php echo $row['age_range'&#93;; ?></td>
<td><?php echo $row['date_of_birth'&#93;; ?></td>
<td><?php echo $row['skin_complexion'&#93;; ?></td>
<td><?php echo $row['height'&#93;; ?></td>
<td><?php echo $row['weight'&#93;; ?></td>
<td><?php echo $row['sexual_orientation'&#93;; ?></td>
<td><?php echo $row['religion'&#93;; ?></td>
<td><?php echo $row['education'&#93;; ?></td>
<td><?php echo $row['profession'&#93;; ?></td>
<td><?php echo $row['marital_status'&#93;; ?></td>
<td><?php echo $row['working_status'&#93;; ?></td>
<td><?php echo $row['country_of_birth'&#93;; ?></td>
<td><?php echo $row['home_town'&#93;; ?></td>
<td><?php echo $row['home_neighbourhood'&#93;; ?></td>
<td><?php echo $row['home_borough'&#93;; ?></td>
<td><?php echo $row['home_council'&#93;; ?></td>
<td><?php echo $row['home_city'&#93;; ?></td>
<td><?php echo $row['home_county'&#93;; ?></td>
<td><?php echo $row['home_district'&#93;; ?></td>
<td><?php echo $row['home_region'&#93;; ?></td>
<td><?php echo $row['home_state'&#93;; ?></td>
<td><?php echo $row['home_country'&#93;; ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php if (ceil($total_pages $num_results_on_page) > 0)&#58; ?>
<ul class="pagination">
<?php if ($page_number 1)&#58; ?>
<li class="prev"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page-1 ?>">Prev</a></li>
<?php endif; ?>

<?php if ($page_number 3)&#58; ?>
<li class="start"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=1">1</a></li>
<li class="dots">...</li>
<?php endif; ?>

<?php if ($page_number-0)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number-2 ?>"><?php echo $page_number-2 ?></a></li><?php endif; ?>
<?php if ($page_number-0)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number-1 ?>"><?php echo $page_number-1 ?></a></li><?php endif; ?>

<li class="currentpage"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?<?php echo $page_number?>"><?php echo $page_number ?></a></li>

<?php if ($page_number+ceil($total_pages $num_results_on_page)+1)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+1 ?>"><?php echo $page_number+1 ?></a></li><?php endif; ?>
<?php if ($page_number+ceil($total_pages $num_results_on_page)+1)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+2 ?>"><?php echo $page_number+2 ?></a></li><?php endif; ?>

<?php if ($page_number ceil($total_pages $num_results_on_page)-2)&#58; ?>
<li class="dots">...</li>
<li class="end"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo ceil($total_pages $num_results_on_page?>"><?php echo ceil($total_pages $num_results_on_page?></a></li>
<?php endif; ?>

<?php if ($page_number ceil($total_pages $num_results_on_page))&#58; ?>
<li class="next"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+1 ?>">Next</a></li>
<?php endif; ?>
</ul>
<?php endif; ?>
</body>
</html>
<?php 
$stmt_1->close(); 

?>


<?php 
include 'footer_account.php'//Required on all webpages of the Account. 
?>



Now, I need to add the search feature and so experimenting with the mysql queries with php.
Look at my current code below.
Look at my Mysql Queries. I am making mistakes there with the "?".
(I used the "?" as place-holders for the Prepared Statements).
I am told my error lies there in the mysql queries.
Q1. How to fix this ?

Q2. For our newbies' learning purposes. Can anyone be kind enough to show a mini pagination script ?
You may leave-out the following as I am likely to manage this with Bootsrap design tutorials:
* Page Design: Responsive Web Design using Html 5 & CSS (latest).

<?php 
//https&#58;//www.w3schools.com/whatis/tryit.asp?filename=trywhatis_bootstrap_table&stacked=h
//Required PHP Files. 
include 'header_account.php'//Required on all webpages of the Account. 
?>


<?php 
if (!$conn

$error mysqli_connect_error(); 
$errno mysqli_connect_errno(); 
print "$errno&#58; $error\n"
exit(); 


$query_type $_GET['query_type'&#93;; 

//If $_GET['query_type'&#93;) is empty then show error as it must be set. 
if(!isset($_GET['query_type'&#93;) && empty($_GET['query_type'&#93;)) 

    echo 
"Invalid Query!"

/*If $_GET['query_type'&#93;) is full with value other than wild-card or "All" 
or "all" then make specific query. 
*/
elseif($query_type != 'all' OR $query_type != 'All' OR $query_type != '*'

    ${
$query_type} = $_GET[$_GET['query_type'&#93;&#93;; 
    
$followed_word = ${$query_type}; //Same as&#58; $_GET[$_GET['query_type'&#93;&#93;; 

    
$stmt_1->$total_pages $conn->query("SELECT * FROM browsing_histories WHERE username = ?")->num_rows
$stmt_1->bind_param('s'$query_type); 
$stmt_1->execute(); 

// Check if the page number is specified and check if it's a number, if not return the default page number which is 1. 
$page_number = isset($_GET['page_number'&#93;) && is_numeric($_GET['page_number'&#93;) ? $_GET['page_number'&#93; &#58; 1; 
//Number of results to show on each page. 
$num_results_on_page 25

if ($stmt_1 $conn->prepare('SELECT * FROM browsing_histories WHERE username = ? ORDER BY id LIMIT ?,?')) { 
// Calculate the page to get the results we need from our table. 
$calc_page = ($page_number 1) * $num_results_on_page
//Added this line according to stackoverflow.com suggestion.
$stmt_2->bind_param('sii'$query_type$num_results_on_page$calc_page); 
//Make the query.     
$stmt_2->execute(); 
    } 

else 
//Make general query or query for all records. 

    
//Grab "all records" from the table. 
    //Get the total number of records from the table&#58; "browsing_histories". 
    
$total_pages $conn->query("SELECT * FROM browsing_histories")->num_rows
    
//Make the query. 
    
$stmt $conn->prepare('SELECT * FROM browsing_histories ORDER BY id LIMIT ?,?'); 
    
$stmt->bind_param('ii'$num_results_on_page); 


$stmt_1->execute(); 
?>


<?php 
include 'footer_account.php'//Required on all webpages of the Account. 
?>


NOTE 1:
The header_account.php includes more files.
The $user is defined via SESSION from one of those included files. So don't worry that I have not defined the $user here. Error reporting is ON and I am not getting any error regarding the $user.


NOTE 2: I would appreciate it if someone modified my code according to my requirements mentioned on my original post and add it to this thread for all newbies to learn from.


NOTE 3: This forum is showing my codes funny. Hence, attached my code file. Attachment will show my code correctly.
1st attachment shows my 1st code that is working fine. I do not need your help on that file.
2nd attachment shows my 2nd code which is not working properly. I need your help on that file.

NOTE 4: The 2nd script is in OOP Style. I only know Procedural. Hence struggling. This is not really my code. I grabbed it from a tutorial and tried adding the search function but failing miserably.

Thanks
« Last Edit: April 08, 2019, 05:07 PM by The Code Queryer »

The Code Queryer

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 33
    • View Profile
    • Donate to Member
No one knows the answer ?  :-\

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Again, check StackOverflow with your questions.  You'll have a larger variety of coders and people to help you.  If someone knows here, they'd be happy to help you, but we have a smaller pool and depending on timeframe they might not be able to answer.

The Code Queryer

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 33
    • View Profile
    • Donate to Member
Again, check StackOverflow with your questions.  You'll have a larger variety of coders and people to help you.  If someone knows here, they'd be happy to help you, but we have a smaller pool and depending on timeframe they might not be able to answer.

Having trouble at StackOverFlow as it says I reached my questioning limit.
How-about you give it ago to answer my questions ?