Folks,
I need your input here:
[code]
//$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 ?
Context:
[code]
$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>”;
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>”; //THIS LINE GETS ECHOED AS prepare_statement() FAILED. WHY IT FAILED ?
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 ?
<i>
</i>$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>";
<i> </i> mysqli_stmt_bind_param($stmt_1,'s',$_GET['keywords']);
<i> </i> mysqli_stmt_execute($stmt_1);
<i> </i> $result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
<i> </i>
<i> </i> mysqli_stmt_fetch($stmt_1);
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>"; //THIS LINE GETS TRIGGERED AND ECHOED IN TEST AS prepare_statement() FAILED. WHY IT FAILED ?
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_1));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
<i> </i> die("A. Prepare failed!");
<i> </i>}
<i> </i>
$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>";
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 62. (THIS LINE GETS TRIGGERED AND ECHOED IN TEST AS prepare_statement() FAILED. WHY IT FAILED ?).
printf("Error: %s.n", mysqli_stmt_error($stmt_1));
printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
die("A. Prepare failed!");
}
````
<i>
</i><form method='GET' action="<?php echo $_SERVER['PHP_SELF'];?>?keywords=$keywords&limit=$limit&page=1">
<i>
</i><?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>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
<i>
</i><?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['search']))//THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS CLICKED.
{
echo __LINE__; echo "<br>"; //LINE 20
<i> </i>pagination();
}
if(!ISSET($_GET['keywords'])) //THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS NOT CLICKED. UT PAGE IS LOADED VIA LINKS (PAGINATION: PAGE 2, PAGE 3, ETC.).
{
echo __LINE__; echo "<br>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
function pagination()
{
if(!ISSET($_GET['keywords']))
{
echo __LINE__; echo "<br>";
<i> </i> die("Type your keywords");
<i> </i>}
<i> </i>//Check if the PAGE RESULT LIMIT is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$limit = ISSET($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 1;
<i> </i>//Check if the PAGE NUMBER is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$page = ISSET($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
<i> </i>$query_1 = "SELECT COUNT(id) FROM links WHERE keywords = ?";
<i> </i>$stmt_1 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_1,$query_1))
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> mysqli_stmt_bind_param($stmt_1,'s',$_GET['keywords']);
<i> </i> mysqli_stmt_execute($stmt_1);
<i> </i> $result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
<i> </i>
<i> </i> mysqli_stmt_fetch($stmt_1);
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>"; //LINE 62
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_1));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
<i> </i> die("A. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_1);
<i> </i>//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
<i> </i>$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?
<i> </i>$offset = (($page * $limit) - $limit);
<i> </i>$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";
<i> </i>$stmt_2 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_2,$query_2))
<i> </i>{
<i> </i> mysqli_stmt_bind_param($stmt_2,"ss",$keywords,$keywords);
<i> </i> mysqli_stmt_execute($stmt_2);
<i> </i> $result_2 = mysqli_stmt_get_result($stmt_2);
<i> </i>
<i> </i> if(!$result_2)
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> die("Fetching Error");
<i> </i> }
<i> </i> while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> echo "LIMIT: $limit<br>";
<i> </i> echo "ROW COUNT: $row_count<br><br>";
<i> </i> echo "TOTAL PAGES: $total_pages<br><br>";
<i> </i>
<i> </i> //Retrieve Values.
<i> </i> $id = $row["id"];
<i> </i> $page_url = $row["page_url"];
<i> </i> $link_anchor_text = $row["link_anchor_text"];
<i> </i> $page_description = $row["page_description"];
<i> </i> $keyphrases= $row["keyphrases"];
<i> </i> $keywords = $row["keywords"];
<i> </i>
<i> </i> echo "Id: $id<br>";
<i> </i> echo "Page Url: $page_url<br>";
<i> </i> echo "Link Anchor Text: $link_anchor_text<br>";
<i> </i> echo "Page Description: $page_description<br>";
<i> </i> echo "Keyphrases: $keyphrases<br>";
<i> </i> echo "Keywords: $keywords<br>";
<i> </i> echo "<br>";
<i> </i> echo "<br>";
<i> </i> }
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_2));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_2));
<i> </i> die("B. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_2);
<i> </i>
<i> </i>if($page>$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
<i> </i>{
<i> </i> echo "?><a href="pagination_test.php?limit=$limit&page=$total_pages">";?><?php echo "<b> Final Page </b>";?></a><?php
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> $i = 1;
<i> </i> while($i<=$total_pages)
<i> </i> {
<i> </i> if($i<$total_pages)
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo " $i ";?></a><?php
<i> </i> }
<i> </i> elseif($i==$page) //Bold the Current Page Number.
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo "<b> $i </b>";?></a><?php
<i> </i> }
<i> </i> $i++;
<i> </i> }
<i> </i>}
}
function form()
{
?>
<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">25</option>
<option value="10">25</option>
<option value="10">50</option>
<option value="10">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>
<?php
}
?>
<i>
</i>if(ISSET($_GET['search']))
{
echo __LINE__; echo "<br>"; //THIS LINE GETS TRIGGERED AND ECHOED IN TEST
<i> </i>pagination();
}
if(!ISSET($_GET['keywords']))
{
echo __LINE__; echo "<br>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
<i>
</i><?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['search']))//THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS CLICKED.
{
echo __LINE__; echo "<br>"; //LINE 20
<i> </i>pagination();
}
if(!ISSET($_GET['keywords'])) //THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS NOT CLICKED. BUT PAGE IS LOADED VIA LINKS (PAGINATION: PAGE 2, PAGE 3, ETC.).
{
echo __LINE__; echo "<br>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
pagination();
function pagination()
{
if(!ISSET($_GET['keywords']))
{
echo __LINE__; echo "<br>";
<i> </i> die("Type your keywords");
<i> </i>}
<i> </i>//Check if the PAGE RESULT LIMIT is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$limit = ISSET($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 1;
<i> </i>//Check if the PAGE NUMBER is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$page = ISSET($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
<i> </i>$query_1 = "SELECT COUNT(id) FROM links WHERE keywords = ?";
<i> </i>$stmt_1 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_1,$query_1))
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> mysqli_stmt_bind_param($stmt_1,'s',$_GET['keywords']);
<i> </i> mysqli_stmt_execute($stmt_1);
<i> </i> $result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
<i> </i>
<i> </i> mysqli_stmt_fetch($stmt_1);
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>"; //LINE 62
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_1));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
<i> </i> die("A. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_1);
<i> </i>//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
<i> </i>$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?
<i> </i>$offset = (($page * $limit) - $limit);
<i> </i>$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";
<i> </i>$stmt_2 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_2,$query_2))
<i> </i>{
<i> </i> mysqli_stmt_bind_param($stmt_2,"ss",$keywords,$keywords);
<i> </i> mysqli_stmt_execute($stmt_2);
<i> </i> $result_2 = mysqli_stmt_get_result($stmt_2);
<i> </i>
<i> </i> if(!$result_2)
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> die("Fetching Error");
<i> </i> }
<i> </i> while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> echo "LIMIT: $limit<br>";
<i> </i> echo "ROW COUNT: $row_count<br><br>";
<i> </i> echo "TOTAL PAGES: $total_pages<br><br>";
<i> </i>
<i> </i> //Retrieve Values.
<i> </i> $id = $row["id"];
<i> </i> $page_url = $row["page_url"];
<i> </i> $link_anchor_text = $row["link_anchor_text"];
<i> </i> $page_description = $row["page_description"];
<i> </i> $keyphrases= $row["keyphrases"];
<i> </i> $keywords = $row["keywords"];
<i> </i>
<i> </i> echo "Id: $id<br>";
<i> </i> echo "Page Url: $page_url<br>";
<i> </i> echo "Link Anchor Text: $link_anchor_text<br>";
<i> </i> echo "Page Description: $page_description<br>";
<i> </i> echo "Keyphrases: $keyphrases<br>";
<i> </i> echo "Keywords: $keywords<br>";
<i> </i> echo "<br>";
<i> </i> echo "<br>";
<i> </i> }
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_2));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_2));
<i> </i> die("B. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_2);
<i> </i>
<i> </i>if($page>$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
<i> </i>{
<i> </i> echo "?><a href="pagination_test.php?limit=$limit&page=$total_pages">";?><?php echo "<b> Final Page </b>";?></a><?php
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> $i = 1;
<i> </i> while($i<=$total_pages)
<i> </i> {
<i> </i> if($i<$total_pages)
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo " $i ";?></a><?php
<i> </i> }
<i> </i> elseif($i==$page) //Bold the Current Page Number.
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo "<b> $i </b>";?></a><?php
<i> </i> }
<i> </i> $i++;
<i> </i> }
<i> </i>}
}
function form()
{
?>
<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">25</option>
<option value="10">25</option>
<option value="10">50</option>
<option value="10">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>
<?php
}
?>
<i>
</i>ini_set('error_reporting','E_ALL');//error_reporting(E_ALL);
<i>
</i>ini_set('error_reporting',E_ALL);//error_reporting(E_ALL);
<i>
</i><?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['search']))//THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS CLICKED.
{
echo __LINE__; echo "<br>"; //LINE 20
<i> </i>pagination();
}
if(!ISSET($_GET['keywords'])) //THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS NOT CLICKED. BUT PAGE IS LOADED VIA LINKS (PAGINATION: PAGE 2, PAGE 3, ETC.).
{
echo __LINE__; echo "<br>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
pagination();
function pagination()
{
if(!ISSET($_GET['keywords']))
{
echo __LINE__; echo "<br>";
<i> </i> die("Type your keywords");
<i> </i>}
<i> </i>//Check if the PAGE RESULT LIMIT is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$limit = ISSET($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 1;
<i> </i>//Check if the PAGE NUMBER is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$page = ISSET($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
<i> </i>$query_1 = "SELECT COUNT(id) FROM links WHERE keywords = ?";
<i> </i>$stmt_1 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_1,$query_1))
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> mysqli_stmt_bind_param($stmt_1,'s',$_GET['keywords']);
<i> </i> mysqli_stmt_execute($stmt_1);
<i> </i> $result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
<i> </i>
<i> </i> mysqli_stmt_fetch($stmt_1);
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>"; //LINE 64
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_1));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
<i> </i> die("A. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_1);
<i> </i>//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
<i> </i>$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?
<i> </i>$offset = (($page * $limit) - $limit);
<i> </i>$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";
<i> </i>$stmt_2 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_2,$query_2))
<i> </i>{
<i> </i> mysqli_stmt_bind_param($stmt_2,"s",$keywords);
<i> </i> mysqli_stmt_execute($stmt_2);
<i> </i> $result_2 = mysqli_stmt_get_result($stmt_2);
<i> </i>
<i> </i> if(!$result_2)
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> die("Fetching Error");
<i> </i> }
<i> </i> while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> echo "LIMIT: $limit<br>";
<i> </i> echo "ROW COUNT: $row_count<br><br>";
<i> </i> echo "TOTAL PAGES: $total_pages<br><br>";
<i> </i>
<i> </i> //Retrieve Values.
<i> </i> $id = $row["id"];
<i> </i> $page_url = $row["page_url"];
<i> </i> $link_anchor_text = $row["link_anchor_text"];
<i> </i> $page_description = $row["page_description"];
<i> </i> $keyphrases= $row["keyphrases"];
<i> </i> $keywords = $row["keywords"];
<i> </i>
<i> </i> echo "Id: $id<br>";
<i> </i> echo "Page Url: $page_url<br>";
<i> </i> echo "Link Anchor Text: $link_anchor_text<br>";
<i> </i> echo "Page Description: $page_description<br>";
<i> </i> echo "Keyphrases: $keyphrases<br>";
<i> </i> echo "Keywords: $keywords<br>";
<i> </i> echo "<br>";
<i> </i> echo "<br>";
<i> </i> }
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_2));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_2));
<i> </i> die("B. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_2);
<i> </i>
<i> </i>if($page>$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
<i> </i>{
<i> </i> echo "?><a href="pagination_test.php?limit=$limit&page=$total_pages">";?><?php echo "<b> Final Page </b>";?></a><?php
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> $i = 1;
<i> </i> while($i<=$total_pages)
<i> </i> {
<i> </i> if($i<$total_pages)
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo " $i ";?></a><?php
<i> </i> }
<i> </i> elseif($i==$page) //Bold the Current Page Number.
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo "<b> $i </b>";?></a><?php
<i> </i> }
<i> </i> $i++;
<i> </i> }
<i> </i>}
}
function form()
{
?>
<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>
<?php
}
?>
<i>
</i><?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
//SCRIPT FLOW STARTS HERE.
echo __LINE__; echo "<br>"; //LINE 16: THIS LINE GETS TRIGGERED AND ECHOED IN TEST
if(ISSET($_GET['search']))//THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS CLICKED.
{
echo __LINE__; echo "<br>"; //LINE 20
<i> </i>pagination();
}
if(!ISSET($_GET['keywords'])) //THIS LINE WILL TRIGGER WHEN 'SEARCH' BUTTON IS NOT CLICKED. BUT PAGE IS LOADED VIA LINKS (PAGINATION: PAGE 2, PAGE 3, ETC.).
{
echo __LINE__; echo "<br>"; echo "<br>";
<i> </i>form();
<i> </i>die;
}
pagination();
//SCRIPT FLOW ENDS HERE.
//ONLY FUNCTION DEFINITIONS FROM THIS POINT ONWARDS
function pagination()
{
require 'conn.php';//Re-added this inside the pagination() function this time as it gives error "undefined $conn" without re-addition.
require 'error_reporting.php'; //Re-added this inside the pagination() function too.
<i> </i>if(!ISSET($_GET['keywords']))
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> die("Type your keywords");
<i> </i>}
<i> </i>//Check if the PAGE RESULT LIMIT is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$limit = ISSET($_GET['limit']) && is_numeric($_GET['limit']) ? $_GET['limit'] : 1;
<i> </i>//Check if the PAGE NUMBER is specified or not and if it's a numer or not. If not, return the default: 1.
<i> </i>$page = ISSET($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
<i> </i>$query_1 = "SELECT COUNT(id) FROM links WHERE keywords = ?";
<i> </i>$stmt_1 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_1,$query_1))
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> mysqli_stmt_bind_param($stmt_1,'s',$_GET['keywords']);
<i> </i> mysqli_stmt_execute($stmt_1);
<i> </i> $result_1 = mysqli_stmt_bind_result($stmt_1,$row_count);
<i> </i>
<i> </i> mysqli_stmt_fetch($stmt_1);
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>"; //LINE 64
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_1));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_1));
<i> </i> die("A. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_1);
<i> </i>//$total_pages = ceil($result_1/$limit); //SHOULD I KEEP THIS LINE OR THE ONE BELOW THIS ONE ?
<i> </i>$total_pages = ceil($row_count/$limit); //SHOULD I KEEP THIS LINE OR THE ONE ABOVE THIS ONE ?
<i> </i>$offset = (($page * $limit) - $limit);
<i> </i>$query_2 = "SELECT id,page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ? ORDER by id LIMIT $offset,$limit";
<i> </i>$stmt_2 = mysqli_stmt_init($conn);
<i> </i>if(mysqli_stmt_prepare($stmt_2,$query_2))
<i> </i>{
<i> </i> mysqli_stmt_bind_param($stmt_2,'s',$keywords);
<i> </i> mysqli_stmt_execute($stmt_2);
<i> </i> $result_2 = mysqli_stmt_get_result($stmt_2);
<i> </i>
<i> </i> if(!$result_2)
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> die("Fetching Error");
<i> </i> }
<i> </i> while($row = mysqli_fetch_array($result_2,MYSQLI_ASSOC))
<i> </i> {
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> echo "LIMIT: $limit<br>";
<i> </i> echo "ROW COUNT: $row_count<br><br>";
<i> </i> echo "TOTAL PAGES: $total_pages<br><br>";
<i> </i>
<i> </i> //Retrieve Values.
<i> </i> $id = $row["id"];
<i> </i> $page_url = $row["page_url"];
<i> </i> $link_anchor_text = $row["link_anchor_text"];
<i> </i> $page_description = $row["page_description"];
<i> </i> $keyphrases= $row["keyphrases"];
<i> </i> $keywords = $row["keywords"];
<i> </i>
<i> </i> echo "Id: $id<br>";
<i> </i> echo "Page Url: $page_url<br>";
<i> </i> echo "Link Anchor Text: $link_anchor_text<br>";
<i> </i> echo "Page Description: $page_description<br>";
<i> </i> echo "Keyphrases: $keyphrases<br>";
<i> </i> echo "Keywords: $keywords<br>";
<i> </i> echo "<br>";
<i> </i> echo "<br>";
<i> </i> }
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> echo __LINE__; echo "<br>";
<i> </i>
<i> </i> printf("Error: %s.n", mysqli_stmt_error($stmt_2));
<i> </i> printf("Error: %d.n", mysqli_stmt_errno($stmt_2));
<i> </i> die("B. Prepare failed!");
<i> </i>}
<i> </i>mysqli_stmt_close($stmt_2);
<i> </i>
<i> </i>if($page>$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
<i> </i>{
<i> </i> echo "?><a href="pagination_test.php?limit=$limit&page=$total_pages">";?><?php echo "<b> Final Page </b>";?></a><?php
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> $i = 1;
<i> </i> while($i<=$total_pages)
<i> </i> {
<i> </i> if($i<$total_pages)
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo " $i ";?></a><?php
<i> </i> }
<i> </i> elseif($i==$page) //Bold the Current Page Number.
<i> </i> {
<i> </i> echo "<a href="pagination_test.php?keywords=$keywords&limit=$limit&page=$i">";?><?php echo "<b> $i </b>";?></a><?php
<i> </i> }
<i> </i> $i++;
<i> </i> }
<i> </i>}
}
function form()
{
?>
<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>
<?php
}
?>
>@developer_web#1622491 No one knows the answer ?
0.1.9 — BETA 4.26