/    Sign up×
Community /Pin to ProfileBookmark

Why mysqli_stmt_bind_result Fails ?

Php Gurus,

I have a mysql tbl “searching_histories”.
It’s columns are:
id|date_and_time |searched_keywords|browsed_page_url |browsed_page_type|referral_page|visitor_username|visitor_type

It’s 3rd entry looks like this:
3 | 2018-07-25 01:13:32|Page Description |http://7search.com/|Information Page |NULL |admin123 |unhappy visitor

Now, I’m trying to write a php script that pulls matches from this mysql tbl.
The following url should have puleld that 3rd entry from my mysql tbl:
http://localhost/test/visitors_stats.php?visitor_type=unhappy_visitors&browsed_page_type=Information%20Page&browsed_page_url=http://7search.com/&links_per_page=25&page_number=

But it does not.
The page fails to pull the data. The page shows like this with hardly any data pulled:
“Search Result:
Visitor Type:
Browsed Page:
Browsed Page Type:
Matches: 0

0 Result Found …

Submission Date & Time in California Usa

Visitor Username:

Visitor Type:

Keywords Search:

Browsed Page:
trailers_stats.php?browsed_page=

Browsed Page Type:

Referral Page:
trailers_stats.php?referral_page=”

Notice, the page shows “matches:0”. There should be a match on the 3rd entry (mysql tbl).
Anyway, here is my full code:

[code]
<?php

//Required PHP Files.
include ‘config.php’;
include ‘header.php’;
include ‘account_header.php’;

if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print “$errno: $errorn”;
exit();
}
else
{
//Get the Page Number. Default is 1 (First Page).
$page_number = $_GET[“page_number”];
if ($page_number == “”)
{
$page_number = 1;
}

$visitor_type = $_GET[“visitor_type”];
$browsed_page_url = $_GET[“browsed_page_url”];
$browsed_page_type = $_GET[“browsed_page_type”];

echo “$visitor_type”;//delete these as getting echoed
echo “$browsed_page_url”;//delete these as getting echoed
echo “$browsed_page_type”;//delete these as getting echoed

$links_per_page = $_GET[“links_per_page”];
if ($links_per_page == “”)
{
$links_per_page = 25;
}

$max_result = 100;
//$offset = ($page_number*$links_per_page)-$links_per_page;
$offset = ($page_number-1)*$links_per_page;

//$query_1 = “SELECT COUNT(*) FROM searching_histories WHERE visitor_type = ?”;
$query_1 = “SELECT COUNT(*) FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ? OFFSET ?”;
$stmt_1 = mysqli_prepare($conn,$query_1);
//mysqli_stmt_bind_param($stmt_1,’sss’,$visitor_type,$browsed_page_url,$browsed_page_type);
mysqli_stmt_bind_param($stmt_1,’sssii’,$visitor_type,$browsed_page_url,$browsed_page_type,$links_per_page,$offset);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
mysqli_stmt_fetch($stmt_1);
mysqli_stmt_free_result($stmt_1);

$total_pages = ceil($matching_rows_count/$links_per_page);
$query_2 = “SELECT id,date_and_time,visitor_username,visitor_type,searched_keywords,browsed_page_url,browsed_page_type,referral_page FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ? OFFSET ?”;
$stmt_2 = mysqli_prepare($conn,$query_2);
mysqli_stmt_bind_param($stmt_2,’sssii’,$visitor_type,$browsed_page_url,$browsed_page_type,$links_per_page,$offset);
mysqli_stmt_execute($stmt_2);
$result_2 = mysqli_stmt_bind_result($stmt_2,$id,$date_and_time,$visitor_username,$visitor_type,$searched_keywords,$browsed_page_url,$browsed_page_type,$referral_page);
mysqli_stmt_fetch($stmt_2);

echo “$visitor_username”;//WHY ARE NOT THESE GETTING ECHOED ?
echo “$visitor_type”;//WHY ARE NOT THESE GETTING ECHOED ?
echo “$searched_keywords”;//WHY ARE NOT THESE GETTING ECHOED ?

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional/EN”>
<html>
<head>
<meta content=”text/html; charset=ISO-8859-1″ http-equiv=” content-type”>
<title><?php echo “Search Result:<br> Visitor Type: $visitor_type<br> Browsed Page: $browsed_page_url<br> Browsed Page Type: $browsed_page_type<br> Matches: $matching_rows_count<br>”; ?></title>
</head>
<body>
<br>
<p align=”center”><span style=”font-weight:bold;”><?php echo “Search Result:<br> Visitor Type: $visitor_type<br> Browsed Page: $browsed_page_url<br> Browsed Page Type: $browsed_page_type<br> Matches: $matching_rows_count<br>”; ?></span></align>
<br>
<br>
<table width=”1500″ border=”0″ cellpadding=”5″ cellspacing=”2″ bgcolor=”#666666″>
<?php if(!$stmt_2)
{
?>
<tr>
<td bgcolor=”#FFFFFF”>No record found! Try another time.</td>
</tr>
<?php
}
else
{
if(($offset+1)<=$max_result)
{
printf(“<b> %d Result Found …</b>n”,$matching_rows_count); ?><br>
<br>
<b>Submission Date & Time in <?php echo “$server_time” ?></b><br><?php printf(“%s”,$date_and_time); ?><br>
<br>
<br>
<b>Visitor Username:</b><br>
<?php printf(“%s”,$visitor_username); ?>
<br>
<br>
<b>Visitor Type:</b><br>
<?php printf(“%s”,$visitor_type); ?>
<br>
<br>
<b>Keywords Search:</b><br>
<?php printf(“%s”,$searched_keywords); ?>
<br>
<br>
<b>Browsed Page:</b><br>
<?php printf(“%s”,”<a href=”trailers_stats.php?browsed_page=$browsed_page_url”>trailers_stats.php?browsed_page=$browsed_page_url</a>”); ?>
<br>
<br>
<b>Browsed Page Type:</b><br>
<?php printf(“%s”,$browsed_page_type); ?>
<br>
<br>
<b>Referral Page:</b><br>
<?php printf(“%s”,”<a href=”trailers_stats.php?referral_page=$referral_page”>trailers_stats.php?referral_page=$referral_page</a>”); ?>
<br>
<br>
<?php
//Use this technique: http://php.net/manual/en/mysqli-stmt.fetch.php
while(mysqli_stmt_fetch($stmt_2))
{
?>
<b>Submission Date & Time in <?php echo “$server_time” ?></b><br><?php printf(“%s”,$date_and_time); ?><br>
<br>
<br>
<b>Visitor Username:</b><br>
<?php printf(“%s”,$visitor_username); ?>
<br>
<br>
<b>Visitor Type:</b><br>
<?php printf(“%s”,$visitor_type); ?>
<br>
<br>
<b>Keywords Search:</b><br>
<?php printf(“%s”,”<a href=”trailers_stats.php?keywords=$keywords_search”>trailers_stats.php?keywords=$keywords_search</a>”); ?>
<br>
<br>
<b>Browsed Page:</b><br>
<?php printf(“%s”,”<a href=”trailers_stats.php?browsed_page=$browsed_page”>trailers_stats.php?browsed_page=$browsed_page</a>”); ?>
<br>
<br>
<b>Browsed Page Type:</b><br>
<?php printf(“%s”,$browsed_page_type); ?>
<br>
<br>
<b>Referral Page:</b><br>
<?php printf(“%s”,”<a href=”trailers_stats.php?referral_page=$referral_page”>trailers_stats.php?referral_page=$referral_page</a>”); ?>
<br>
<br>
<tr name=”pagination”>
<td colspan=”10″ bgcolor=”#FFFFFF”> Result Pages:
<?php
if($page_number<$total_pages)
{
for($i=1;$i<=$total_pages;$i++) //Show Page Numbers in Serial Order. Eg. 1,2,3.
echo “<a href=”{$_SERVER[‘PHP_SELF’]}?user=$user&page_number={$i}”>{$i}</a> “;
}
else
{
for($i=$total_pages;$i>=1;$i–) //Show Page Numbers in Reverse Order. Eg. 3,2,1.
echo “<a href=”{$_SERVER[‘PHP_SELF’]}?user=$user&page_number={$i}”>{$i}</a> “;
}
?>
</td>
</tr>
<?php
}
}
}
?>
</table>
<br>
<br>
<p align=”center”><span style=”font-weight:bold;”><?php echo “Search Result:<br> Visitor Type: $visitor_type<br> Browsed Page: $browsed_page_url<br> Browsed Page Type: $browsed_page_type<br> Matches: $matching_rows_count<br>”; ?></span></align>
<br>
</div>
<br>
</body>
</html>
<?php
//Free Result Set.
mysqli_stmt_free_result($stmt_2);
//Close Statement Connection.
mysqli_stmt_close($stmt_2);
//Close Database Connection.
mysqli_close($conn);
}
?>
[/code]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@site-developerauthorJul 25.2018 — Solved the problem.

This url is now pulling the tbl data:

http://localhost/test/visitors_stats.php?visitor_type=unhappy%20visitor&browsed_page_type=Information%20Page&browsed_page_url=http://7search.com/&links_per_page=25&page_number=

The entry in mysql tbl was "unhappy visitor" and so I never should have added "unhappy_visitor" in the url.
Copy linkTweet thisAlerts:
@site-developerauthorAug 01.2018 — A new problem.

Q1. This url:

http://localhost/test/visits_stats.php?SearchResult_VisitorType=lost%20visitor&SearchResult_BrowsedPageType=Intangibles&SearchResult_BrowsedPageUrl=http://go2.com/&LinksPerPage=25&PageNumber=

fails to find any match in mysql tbl with this bound param:
<i>
</i>mysqli_stmt_bind_param($stmt_1,'sssii',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType,$LinksPerPage,$offset); //THIS BOUND PARAM IS MATCHING 0 RECORD, WHEN BELOW BOUND PARAM MATCHES 1 RECORD !!!


But manages to query and find 1 match with this bound param:
<i>
</i>mysqli_stmt_bind_param($stmt_1,'sssii',$_GET["SearchResult_VisitorType"],$_GET["SearchResult_BrowsedPageUrl"],$_GET["SearchResult_BrowsedPageType"],$LinksPerPage,$offset); //THIS BOUND PARAM MATCHES 1 RECORD

How so ?

Q2. Since this bound param:
<i>
</i>mysqli_stmt_bind_param($stmt_1,'sssii',$_GET["SearchResult_VisitorType"],$_GET["SearchResult_BrowsedPageUrl"],$_GET["SearchResult_BrowsedPageType"],$LinksPerPage,$offset); //THIS QUERY MATCHES 1 RECORD

manages to find 1 match then how come the result is not getting bound as the following echoes fail:

<i>
</i>echo "1. $SearchResult_VisitorType"; //THESE ARE NOT GETTING ECHOED EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD
echo "2. $SearchResult_BrowsedPageType"; //THESE ARE NOT GETTING EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD
echo "3. $SearchResult_BrowsedPageUrl"; //THESE ARE NOT GETTING EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD


For some reason this line is failing:
<i>
</i>$result_2 = mysqli_stmt_bind_result($stmt_2,$SearchResult_id,$SearchResult_VisitDateAndTime,$SearchResult_VisitorUsername,$SearchResult_VisitorType,$SearchResult_SearchedKeywords,$SearchResult_BrowsedPageUrl,$SearchResult_BrowsedPageType,$SearchResult_ReferralPageUrl);
mysqli_stmt_fetch($stmt_2);


Here is the full script:
<i>
</i>&lt;?php

//Required PHP Files.
include 'config.php';
include 'header.php';
include 'account_header.php';

if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print "$errno: $errorn";
exit();
}
else
{
//Get the Page Number. Default is 1 (First Page).
$PageNumber = $_GET["PageNumber"];
if ($PageNumber == "")
{
$PageNumber = 1;
}

<i> </i>$LinksPerPage = $_GET["LinksPerPage"];
<i> </i>if ($LinksPerPage == "")
<i> </i>{
<i> </i> $LinksPerPage = 1;
<i> </i>}
<i> </i>
<i> </i>$max_result = 100;
<i> </i>//$offset = ($PageNumber*$LinksPerPage)-$LinksPerPage;
<i> </i>$offset = ($PageNumber-1)*$LinksPerPage;
<i> </i>
<i> </i>$Search_VisitorType = $_GET["SearchResult_VisitorType"];
<i> </i>$search_BrowsedPageType = $_GET["SearchResult_BrowsedPageType"];
<i> </i>$Search_BrowsedPageUrl = $_GET["SearchResult_BrowsedPageUrl"];
<i> </i>
<i> </i>echo "$Search_VisitorType"; //GETS ECHOED
<i> </i>echo "$search_BrowsedPageType"; //GETS ECHOED
<i> </i>echo "$Search_BrowsedPageUrl"; //GETS ECHOED
<i> </i>
<i> </i>$query_1 = "SELECT COUNT(*) FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ? OFFSET ?";
<i> </i>$stmt_1 = mysqli_prepare($conn,$query_1);
<i> </i>mysqli_stmt_bind_param($stmt_1,'sssii',$_GET["SearchResult_VisitorType"],$_GET["SearchResult_BrowsedPageUrl"],$_GET["SearchResult_BrowsedPageType"],$LinksPerPage,$offset); //THIS QUERY MATCHES 1 RECORD
<i> </i>//mysqli_stmt_bind_param($stmt_1,'sssii',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType,$LinksPerPage,$offset); //THIS QUESRY IS MATCHING 0 RECORD, WHEN ABOVE QUERY MATCHES 1 RECORD !!!
<i> </i>mysqli_stmt_execute($stmt_1);
<i> </i>$result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
<i> </i>mysqli_stmt_fetch($stmt_1);
<i> </i>mysqli_stmt_free_result($stmt_1);
<i> </i>
<i> </i>$total_pages = ceil($matching_rows_count/$LinksPerPage);
<i> </i>$query_2 = "SELECT id,date_and_time,visitor_username,visitor_type,searched_keywords,browsed_page_url,browsed_page_type,referral_page_url FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ? OFFSET ?";
<i> </i>$stmt_2 = mysqli_prepare($conn,$query_2);
<i> </i>mysqli_stmt_bind_param($stmt_2,'sssii',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType,$LinksPerPage,$offset);
<i> </i>mysqli_stmt_execute($stmt_2);
<i> </i>$result_2 = mysqli_stmt_bind_result($stmt_2,$SearchResult_id,$SearchResult_VisitDateAndTime,$SearchResult_VisitorUsername,$SearchResult_VisitorType,$SearchResult_SearchedKeywords,$SearchResult_BrowsedPageUrl,$SearchResult_BrowsedPageType,$SearchResult_ReferralPageUrl);
<i> </i>mysqli_stmt_fetch($stmt_2);
<i> </i>
<i> </i>echo "1. $SearchResult_VisitorType"; //THESE ARE NOT GETTING ECHOED EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD
<i> </i>echo "2. $SearchResult_BrowsedPageType"; //THESE ARE NOT GETTING EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD
<i> </i>echo "3. $SearchResult_BrowsedPageUrl"; //THESE ARE NOT GETTING EVEN WHEN MYSQL QUERY IS MATCHING 1 RECORD
<i> </i>
<i> </i>?&gt;
<i> </i>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"&gt;
<i> </i>&lt;html&gt;
<i> </i>&lt;head&gt;
<i> </i>&lt;meta content="text/html; charset=ISO-8859-1" http-equiv=" content-type"&gt;
<i> </i>&lt;title&gt;&lt;?php echo "Search Result:&lt;br&gt; Visitor Type: $Search_VisitorType &lt;br&gt;Browsed Page Type: $search_BrowsedPageType &lt;br&gt;Browsed Page: $Search_BrowsedPageUrl &lt;br&gt;Matches: $matching_rows_count &lt;br&gt;"; ?&gt;&lt;/title&gt;
<i> </i>&lt;/head&gt;
<i> </i>&lt;body&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;p align="left"&gt;&lt;span style="font-weight:bold;"&gt;&lt;?php echo "Search Result:&lt;br&gt; Visitor Type: $Search_VisitorType &lt;br&gt;Browsed Page Type: $Search_BrowsedPageType &lt;br&gt;Browsed Page: $Search_BrowsedPageUrl &lt;br&gt;Matches: $matching_rows_count &lt;br&gt;"; ?&gt;&lt;/span&gt;&lt;/align&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"&gt;
<i> </i>&lt;?php if(!$stmt_2)
<i> </i>{
<i> </i> ?&gt;
<i> </i> &lt;tr&gt;
<i> </i> &lt;td bgcolor="#FFFFFF"&gt;No record found! Try another time.&lt;/td&gt;
<i> </i> &lt;/tr&gt;
<i> </i> &lt;?php
<i> </i>}
<i> </i>else
<i> </i>{
<i> </i> if(($offset+1)&lt;=$max_result)
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;p align="left"&gt;
<i> </i> &lt;b&gt;Visit Date &amp; Time in &lt;?php echo "$server_time" ?&gt;&lt;/b&gt;&lt;br&gt;&lt;?php printf("%s",$SearchResult_VisitDateAndTime); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Searched Keywords:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=SearchedKeywords&amp;SearchedKeywords=$SearchResult_SearchedKeywords&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_SearchedKeywords&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Visitor Type:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=VisitorType&amp;VisitorType=$SearchResult_VisitorType&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_VisitorType&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Browsed Page Type:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=BrowsedPageType&amp;BrowsedPageType=$SearchResult_BrowsedPageType&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_BrowsedPageType&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Browsed Page:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=BrowsedPageUrl&amp;BrowsedPageUrl=$SearchResult_BrowsedPageUrl&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_BrowsedPageUrl&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Referral Page:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=ReferralPageUrl&amp;ReferralPageUrl=$SearchResult_ReferralPageUrl&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_ReferralPageUrl&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Visitor Username:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=VisitorUsername&amp;VisitorUsername=$SearchResult_VisitorUsername&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_VisitorUsername&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;/align&gt;
<i> </i> &lt;?php
<i> </i> //Use this technique: http://php.net/manual/en/mysqli-stmt.fetch.php
<i> </i> while(mysqli_stmt_fetch($stmt_2))
<i> </i> {
<i> </i> ?&gt;
<i> </i> &lt;p align="left"&gt;
<i> </i> &lt;b&gt;Visit Date &amp; Time in &lt;?php echo "$server_time" ?&gt;&lt;/b&gt;&lt;br&gt;&lt;?php printf("%s",$SearchResult_VisitDateAndTime); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Searched Keywords:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=SearchedKeywords&amp;SearchedKeywords=$SearchResult_SearchedKeywords&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_SearchedKeywords&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Visitor Type:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=VisitorType&amp;VisitorType=$SearchResult_VisitorType&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_VisitorType&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Browsed Page Type:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=BrowsedPageType&amp;BrowsedPageType=$SearchResult_BrowsedPageType&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_BrowsedPageType&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Browsed Page:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=BrowsedPageUrl&amp;BrowsedPageUrl=$SearchResult_BrowsedPageUrl&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_BrowsedPageUrl&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Referral Page:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=ReferralPageUrl&amp;ReferralPageUrl=$SearchResult_ReferralPageUrl&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_ReferralPageUrl&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;b&gt;Visitor Username:&lt;/b&gt;&lt;br&gt;
<i> </i> &lt;?php printf("%s","&lt;a href="trails_stats.php?stat_type=VisitorUsername&amp;VisitorUsername=$SearchResult_VisitorUsername&amp;LinksPerPage=25&amp;PageNumber="&gt;$SearchResult_VisitorUsername&lt;/a&gt;"); ?&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;br&gt;
<i> </i> &lt;/align&gt;
<i> </i> &lt;tr name="pagination"&gt;
<i> </i> &lt;td colspan="10" bgcolor="#FFFFFF"&gt; Result Pages:
<i> </i> &lt;?php
<i> </i> if($PageNumber&lt;$total_pages)
<i> </i> {
<i> </i> for($i=1;$i&lt;=$total_pages;$i++) //Show Page Numbers in Serial Order. Eg. 1,2,3.
<i> </i> echo "&lt;a href="{$_SERVER['PHP_SELF']}?user=$user&amp;VisitorType=$Search_VisitorType&amp;SearchResult_BrowsedPageType=$Search_BrowsedPageType&amp;SearchResult_BrowsedPageUrl=$Search_BrowsedPageUrl&amp;PageNumber={$i}"&gt;{$i}&lt;/a&gt; ";
<i> </i> }
<i> </i> else
<i> </i> {
<i> </i> for($i=$total_pages;$i&gt;=1;$i--) //Show Page Numbers in Reverse Order. Eg. 3,2,1.
<i> </i> echo "&lt;a href="{$_SERVER['PHP_SELF']}?user=$user&amp;SearchResult_VisitorType=$Search_VisitorType&amp;SearchResult_BrowsedPageType=$Search_BrowsedPageType&amp;SearchResult_BrowsedPageUrl=$Search_BrowsedPageUrl&amp;PageNumber={$i}"&gt;{$i}&lt;/a&gt; ";
<i> </i> }
<i> </i> ?&gt;
<i> </i> &lt;/td&gt;
<i> </i> &lt;/tr&gt;
<i> </i> &lt;?php
<i> </i> }
<i> </i> }
<i> </i>}
<i> </i>?&gt;
<i> </i>&lt;/table&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;p align="center"&gt;&lt;span style="font-weight:bold;"&gt;&lt;?php echo "Search Result:&lt;br&gt; Visitor Type: $Search_VisitorType &lt;br&gt;Browsed Page Type: $Search_BrowsedPageType &lt;br&gt;Browsed Page: $Search_BrowsedPageUrl &lt;br&gt;Matches: $matching_rows_count &lt;br&gt;"; ?&gt;&lt;/span&gt;&lt;/align&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;/div&gt;
<i> </i>&lt;br&gt;
<i> </i>&lt;/body&gt;
<i> </i>&lt;/html&gt;
<i> </i>&lt;?php
<i> </i>//Free Result Set.
<i> </i>mysqli_stmt_free_result($stmt_2);
<i> </i>//Close Statement Connection.
<i> </i>mysqli_stmt_close($stmt_2);
<i> </i>//Close Database Connection.
<i> </i>mysqli_close($conn);
}
?&gt;


A great mystery! Can anyone solve this mystery ?

Thanks!
Copy linkTweet thisAlerts:
@site-developerauthorAug 03.2018 — Bump!

Need answer to my previous post!
Copy linkTweet thisAlerts:
@ginerjmAug 03.2018 — Perhaps you need to be doing some debugging while awaiting a response here. Personally it is way too much code to wade thru and try to follow. Add some echos intermittently to try to isolate what is truly happening and see what comes up.
Copy linkTweet thisAlerts:
@NogDogAug 03.2018 — Define "doesn't work". Is there an error, or just not getting the result you expect? If the former, what error do you get (maybe have to check the php logs)? If the latter, try echoing out the query you are using, and double check that any variable you are binding to it have the expected values, and then perhaps try running it directly against your DB with those values to see if it does what you really think it does.

In any case, do not dump your entire file with mostly unrelated code to the actual problem here. Also, I'm a big fan of typing SQL across multiple lines instead of one long line. (A newline character takes the same amount of memory as a space.)
``<i>
</i>$query_2 = "SELECT
id,
date_and_time,
visitor_username,
visitor_type,
searched_keywords,
browsed_page_url,
browsed_page_type,
referral_page_url
FROM searching_histories
WHERE
visitor_type = ? AND
browsed_page_url = ? AND
browsed_page_type = ?
ORDER BY id LIMIT ? OFFSET ?"; <i>
</i>
`</CODE>

Which, now that I just edited that example, I suspect that you are not allowed to use bound parameters for limit and offset, but I'm not 100% sure. (In PostgreSQL it won't let you, but I've not used MySQL in a long time now, so am not entirely certain.) You may want to do something like:
<CODE>
`<i>
</i>". . .
ORDER BY id LIMIT ".intval($limit)." OFFSET ".intval($offset);<i>
</i>
``


PS: Just using hypothetical variable names above for limit and offset -- be sure to use the actual names. ?
Copy linkTweet thisAlerts:
@site-developerauthorAug 04.2018 — NogDog,

Error reporting is on on one of the included files. Like this:
<i>
</i>&lt;?php

//ERROR REPORTING CODES.
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

?&gt;


I tried your suggestion but the result is the same as with my query.

I see no errors with my query and I see no errors with your query.

Here is how I set your sugegsted query. My ones are commented-out so people can see the variety of different queries I tried:
<i>
</i>//$query_1 = "SELECT COUNT(*) FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ? OFFSET ?";
$query_1 = "SELECT COUNT(*) FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ".intval($max_result)." OFFSET ".intval($offset);

<i> </i>$stmt_1 = mysqli_prepare($conn,$query_1);
<i> </i>//mysqli_stmt_bind_param($stmt_1,'sssii',$_GET["SearchResult_VisitorType"],$_GET["SearchResult_BrowsedPageUrl"],$_GET["SearchResult_BrowsedPageType"],$LinksPerPage,$offset); //THIS QUERY MATCHES 1 RECORD
<i> </i>//mysqli_stmt_bind_param($stmt_1,'sssii',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType,$LinksPerPage,$offset); //THIS QUESRY IS MATCHING 0 RECORD, WHEN ABOVE QUERY MATCHES 1 RECORD !!!
<i> </i>mysqli_stmt_bind_param($stmt_1,'sss',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType); //THIS QUESRY IS MATCHING 0 RECORD, WHEN ABOVE QUERY MATCHES 1 RECORD !!!
<i> </i>mysqli_stmt_execute($stmt_1);
<i> </i>$result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
<i> </i>mysqli_stmt_fetch($stmt_1);
<i> </i>mysqli_stmt_free_result($stmt_1);
<i> </i>
<i> </i>$total_pages = ceil($matching_rows_count/$LinksPerPage);
<i> </i>$query_2 = "SELECT id,date_and_time,visitor_username,visitor_type,searched_keywords,browsed_page_url,browsed_page_type,referral_page_url FROM searching_histories WHERE visitor_type = ? AND browsed_page_url = ? AND browsed_page_type = ? ORDER BY id LIMIT ".intval($max_result)." OFFSET ".intval($offset);
<i> </i>$stmt_2 = mysqli_prepare($conn,$query_2);
<i> </i>//mysqli_stmt_bind_param($stmt_2,'sssii',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType,$LinksPerPage,$offset); //THIS QUESRY IS MATCHING 0 RECORD, WHEN ABOVE QUERY MATCHES 1 RECORD !!!
<i> </i>mysqli_stmt_bind_param($stmt_2,'sss',$Search_VisitorType,$Search_BrowsedPageUrl,$Search_BrowsedPageType);
<i> </i>mysqli_stmt_execute($stmt_2);
<i> </i>$result_2 = mysqli_stmt_bind_result($stmt_2,$SearchResult_id,$SearchResult_VisitDateAndTime,$SearchResult_VisitorUsername,$SearchResult_VisitorType,$SearchResult_SearchedKeywords,$SearchResult_BrowsedPageUrl,$SearchResult_BrowsedPageType,$SearchResult_ReferralPageUrl);
<i> </i>mysqli_stmt_fetch($stmt_2);
×

Success!

Help @site-developer 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.29,
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,
)...