Folks,
This script is the same as the one here:
Only difference is that, over there I neated the code up y adding them into custom functions.
Over here, I drew them out of the functions and deleted the functions.
Compare both thread’s latest code and see for yourselves, if you got the time.
Anyway, running the script, I get echoed these text:
**16
37
1
Form displays at the bottom of these texts.
TEST:
What I did was, I typed the keyword “heman” and selected “1” from the drop down so script shows 1 result or tbl row per page.
I see now rows. No results. Even though the word “heman” exists in the tbl entry under the col “keywords’.
Tbl: links
conn.php
[code]
<?php
$server = ‘localhost’;
$db_user = ‘root’;
$db_password = ”;
$db = ‘test’;
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect($server,$db_user,$db_password,$db);
mysqli_set_charset($conn,’utf8mb4′);
if(mysqli_connect_error())
{
echo “Mysqli Connection Error” . mysqli_connect_error();
}
elseif(mysqli_connect_errno())
{
echo “Mysqli Connection Error Number” . mysqli_connect_errno();
}
?>
error_reporting.php
[code]
<?php
//https://phpdelusions.net/articles/error_reporting
ini_set(‘display_errors’,’1′);
ini_set(‘display_startup_errors’,’1′);
ini_set(‘error_reporting’,’E_ALL’);//error_reporting(E_ALL);
?>
pagination_test_.php
[code]
<?php
require ‘conn.php’;
require ‘error_reporting.php’;
?>
<!DOCTYPE HTML”>
<html>
<head>
<meta name=”viewport” content=”width-device=width, initial-scale=1″>
</head>
<body>
<?php
echo __LINE__; echo “<br>”; //LINE 16: THIS LINE GETS TRIGGERED AND ECHOED IN TEST
if(!ISSET($_GET[‘keywords’]))
{
echo __LINE__; echo “<br>”;
die(“Type your keywords”);
}
$keyword = $_GET[‘keywords’];
//Check if the PAGE NUMBER is specified or not and if it’s a numer or not. If not, return the default: 1.
$page = ISSET($_GET[‘page’]) && is_numeric($_GET[‘page’]) ? $_GET[‘page’] : 1;
//Check if the PAGE RESULT LIMIT is specified or not and if it’s a numer or not. If not, return the default: 1.
$limit = ISSET($_GET[‘limit’]) && is_numeric($_GET[‘limit’]) ? $_GET[‘limit’] : 1;
$query_1 = “SELECT COUNT(id) FROM links WHERE keywords = ?”;
$stmt_1 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_1,$query_1))
{
echo __LINE__; echo “<br>”;//LINE 37: THIS LINE GETS TRIGGERED AND ECHOED IN TEST
mysqli_stmt_bind_param($stmt_1,’s’,$_GET[‘keywords’]);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
mysqli_stmt_fetch($stmt_1);
}
else
{
echo __LINE__; echo “<br>”; //LINE 47
printf(“Error: %s.n”, mysqli_stmt_error($stmt_1));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_1));
die(“A. Prepare failed!”);
}
mysqli_stmt_close($stmt_1);
//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?
$offset = (($page * $limit) – $limit);
$query_2 = “SELECT id,page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ? OR keyphrases = ? ORDER by id LIMIT $offset,$limit”;
$stmt_2 = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt_2,$query_2))
{
mysqli_stmt_bind_param($stmt_2,”ss”,$keywords,$keywords);
mysqli_stmt_execute($stmt_2);
$result_2 = mysqli_stmt_get_result($stmt_2);
if(!$result_2)
{
echo __LINE__; echo “<br>”;
die(“Fetching Error”);
}
while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
{
echo __LINE__; echo “<br>”;
echo “LIMIT: $limit<br>”;
echo “ROW COUNT: $row_count<br><br>”;
echo “TOTAL PAGES: $total_pages<br><br>”;
//Retrieve Values.
$id = $row[“id”];
$page_url = $row[“page_url”];
$link_anchor_text = $row[“link_anchor_text”];
$page_description = $row[“page_description”];
$keyphrases= $row[“keyphrases”];
$keywords = $row[“keywords”];
echo “Id: $id<br>”;
echo “Page Url: $page_url<br>”;
echo “Link Anchor Text: $link_anchor_text<br>”;
echo “Page Description: $page_description<br>”;
echo “Keyphrases: $keyphrases<br>”;
echo “Keywords: $keywords<br>”;
echo “<br>”;
echo “<br>”;
}
}
else
{
echo __LINE__; echo “<br>”;
printf(“Error: %s.n”, mysqli_stmt_error($stmt_2));
printf(“Error: %d.n”, mysqli_stmt_errno($stmt_2));
die(“B. Prepare failed!”);
}
mysqli_stmt_close($stmt_2);
if($page>$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
{
echo “?><a href=”pagination_test.php?limit=$limit&page=$total_pages”>”;?><?php echo “<b> Final Page </b>”;?></a><?php
}
else
{
$i = 1;
while($i<=$total_pages)
{
if($i<$total_pages)
{
echo “<a href=”pagination_test.php?keywords=$keywords&limit=$limit&page=$i”>”;?><?php echo ” $i “;?></a><?php
}
elseif($i==$page) //Bold the Current Page Number.
{
echo “<a href=”pagination_test.php?keywords=$keywords&limit=$limit&page=$i”>”;?><?php echo “<b> $i </b>”;?></a><?php
}
$i++;
}
}
?>
<form method=’GET’ action=”<?php echo $_SERVER[‘PHP_SELF’];?>?keywords=$keywords&limit=$limit&page=1″>
<label for=”keywords”>Keywords:*</label>
<input type=”text” name=”keywords” id=”keywords” placeholder=”Input Keywords” required>
<br>
<label for=”limit”>Results per Page</label>
<select name=”limit” id=”limit”>
<option value=”1″>1</option>
<option value=”10″>10</option>
<option value=”25″>25</option>
<option value=”50″>50</option>
<option value=”100″>100</option>
</select>
<br>
<button name=”search” id=”search” value=” “>Search</button><br>
<button type=”submit” name=”search” id=”search” value=”search”>Search</button>
<br>
<input type=”reset”>
<br>
</form>
What is wrong ? Why are not the results getting displayed ?