/    Sign up×
Community /Pin to ProfileBookmark

Why No Row Displays ?

Folks,

This script is the same as the one here:
https://www.webdeveloper.com/d/390902-dealing-with-php-ceil
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();
}

?>

[/code]

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);
?>

[/code]

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>

[/code]

What is wrong ? Why are not the results getting displayed ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@developer_webauthorAug 08.2020 — Here is my latest code.

It is similar to the code here:

https://www.webdeveloper.com/d/390902-dealing-with-php-ceil/7

Only difference is, that other thread has it's code inside functions (form(), pagination()) to neaten up the code while this code doesn't make use of functions.

Test result:

I get echoed these:

36

57

1

First two are line numbers (echo __LINE__).

Last one is PAGE 1 link belonging to pagination section at the bottom of the page.

I did a search for KW "heman" in link tbl. It has two entries with that keyword. One entry/row per page should be showed and so 2 pages should show the two rows. That means, result should be spread across two pages but pagination section only shows PAGE 1. It should show page1 and page2 links like this:

12

But shows this nonsense instead:

1

And shows no result on page 1.

Why rows not displaying and how to fix the pagination section ?

Pagination part I wrote like this ....

Current page number should bold.

If the current page is greater than the total pages (eg. only 10 pages show result but someone typed 20 in the url to go to page 20) then that page (eg page 20) should only contain one link pointing to the final page (eg page 10).
<i>
</i>if($page&gt;$total_pages) //If Page Number is greater than Total Pages, show only a link to FINAL PAGE.
{
echo "?&gt;&lt;a href="pagination_test.php?limit=$limit&amp;page=$total_pages"&gt;";?&gt;&lt;?php echo "&lt;b&gt; Final Page &lt;/b&gt;";?&gt;&lt;/a&gt;&lt;?php
}
else
{
$i = 1;
while($i&lt;=$total_pages)
{
if($i&lt;$total_pages)
{
echo "&lt;a href="pagination_test.php?keywords=$keywords&amp;limit=$limit&amp;page=$i"&gt;";?&gt;&lt;?php echo " $i ";?&gt;&lt;/a&gt;&lt;?php
}
elseif($i==$page) //Bold the Current Page Number.
{
echo "&lt;a href="pagination_test.php?keywords=$keywords&amp;limit=$limit&amp;page=$i"&gt;";?&gt;&lt;?php echo "&lt;b&gt; $i &lt;/b&gt;";?&gt;&lt;/a&gt;&lt;?php
}
$i++;
}
}


Anyway, context ....

conn.php
<i>
</i>&lt;?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();
}

?&gt;



error_reporting.php
<i>
</i>&lt;?php

ini_set('display_errors','1');
ini_set('display_startup_errors','1');
ini_set('error_reporting',E_ALL);//error_reporting(E_ALL);
?&gt;



pagination_test_.php
<i>
</i>&lt;?php
require 'conn.php';
require 'error_reporting.php';
?&gt;

&lt;!DOCTYPE HTML"&gt;
&lt;html&gt;

&lt;head&gt;
&lt;meta name="viewport" content="width-device=width, initial-scale=1"&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form method='GET' action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;?keywords=$keywords&amp;limit=$limit&amp;page=1"&gt;
&lt;label for="keywords"&gt;Keywords:*&lt;/label&gt;
&lt;input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required&gt;
&lt;br&gt;
&lt;label for="limit"&gt;Results per Page&lt;/label&gt;
&lt;select name="limit" id="limit"&gt;
&lt;option value="1"&gt;1&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;option value="25"&gt;25&lt;/option&gt;
&lt;option value="50"&gt;50&lt;/option&gt;
&lt;option value="100"&gt;100&lt;/option&gt;
&lt;/select&gt;
&lt;br&gt;
&lt;button name="search" id="search" value=" "&gt;Search&lt;/button&gt;&lt;br&gt;
&lt;button type="submit" name="search" id="search" value="search"&gt;Search&lt;/button&gt;
&lt;br&gt;
&lt;input type="reset"&gt;
&lt;br&gt;
&lt;/form&gt;

&lt;?php

echo __LINE__; echo "&lt;br&gt;"; //LINE 16: THIS LINE GETS TRIGGERED AND ECHOED IN TEST

if(!ISSET($_GET['keywords']))
{
echo __LINE__; echo "&lt;br&gt;";

<i> </i>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']) &amp;&amp; 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']) &amp;&amp; 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 "&lt;br&gt;";//LINE 57: THIS LINE GETS TRIGGERED AND ECHOED IN TEST

<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);
}
else
{
echo __LINE__; echo "&lt;br&gt;"; //LINE 67

<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!");
}

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 = ? 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,"s",$keywords);
mysqli_stmt_execute($stmt_2);
$result_2 = mysqli_stmt_get_result($stmt_2);

<i> </i>if(!$result_2)
<i> </i>{
<i> </i> echo __LINE__; echo "&lt;br&gt;";
<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 "&lt;br&gt;";
<i> </i>
<i> </i> echo "LIMIT: $limit&lt;br&gt;";
<i> </i> echo "ROW COUNT: $row_count&lt;br&gt;&lt;br&gt;";
<i> </i> echo "TOTAL PAGES: $total_pages&lt;br&gt;&lt;br&gt;";
<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&lt;br&gt;";
<i> </i> echo "Page Url: $page_url&lt;br&gt;";
<i> </i> echo "Link Anchor Text: $link_anchor_text&lt;br&gt;";
<i> </i> echo "Page Description: $page_description&lt;br&gt;";
<i> </i> echo "Keyphrases: $keyphrases&lt;br&gt;";
<i> </i> echo "Keywords: $keywords&lt;br&gt;";
<i> </i> echo "&lt;br&gt;";
<i> </i> echo "&lt;br&gt;";
<i> </i>}
}
else
{
echo __LINE__; echo "&lt;br&gt;";//Line 122

<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!");
}

mysqli_stmt_close($stmt_2);

if($page&gt;$total_pages) //If Page Numer is greater than Total Pages, show only a link to FINAL PAGE.
{
echo "?&gt;&lt;a href="pagination_test.php?limit=$limit&amp;page=$total_pages"&gt;";?&gt;&lt;?php echo "&lt;b&gt; Final Page &lt;/b&gt;";?&gt;&lt;/a&gt;&lt;?php
}
else
{
$i = 1;
while($i&lt;=$total_pages)
{
if($i&lt;$total_pages)
{
echo "&lt;a href="pagination_test.php?keywords=$keywords&amp;limit=$limit&amp;page=$i"&gt;";?&gt;&lt;?php echo " $i ";?&gt;&lt;/a&gt;&lt;?php
}
elseif($i==$page) //Bold the Current Page Number.
{
echo "&lt;a href="pagination_test.php?keywords=$keywords&amp;limit=$limit&amp;page=$i"&gt;";?&gt;&lt;?php echo "&lt;b&gt; $i &lt;/b&gt;";?&gt;&lt;/a&gt;&lt;?php
}
$i++;
}
}
?&gt;

×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...