Jump to content

PAGINATION - From Non-Prepared Statement To Prepared Statement Version


phpsane

Recommended Posts

Php Wizards,

 

Check these 2 codes out. Both are PAGINATION. But the first one is without Prepared Statements and the last one is with it.

First one I grabbed 2-3yrs ago online from somewhere. A little editing has gone into it, though.

The purpose of this thread is the latter code. That code is mine. I tried converting the first code (somebody else's code) into using Prepared Statements and have  made quite a mess of things. Landed myself into a very smelly pickle!

Now, before I get roasted (out of the frying pan into the fire), I thought wise to ask you guys to chime in.

Aid me to weed-out as many unnecessary variables and lines of code as possible. Let me know where I am going wrong. What I should change. Or better, show me a little sample (if you want to).

You use urls like these to get the script to grab the data from the mysql tbl. NOTE: Note the "Result_SearchType" GETs on each url.

http://localhost/test/links_stats.php?Result_SearchType=Domain&Result_PageType=Information Page&Result_Domain=go2.com&Result_LinksPerPage=25&Result_PageNumber=

http://localhost/test/links_stats.php?Result_SearchType=Page&Result_PageType=Information Page&Result_Page=http://go2.com/2.html&Result_LinksPerPage=25&Result_PageNumber=

http://localhost/test/links_stats.php?Result_SearchType=Keywords&Result_PageType=Information Page&Result_Keywords=go2&Result_LinksPerPage=25&Result_PageNumber=1

If you really must know. I actually need you to check if the  mysql QUERIES are ok or not as I have a feeling they are not. Need help in the LIMIT and OFFSET so the PAGINATION is done correctly with their help.

I am told to forget the QUERY_1 that deals with the COUNT(*) and just stick with QUERY_2 that pulls the data. I need your advice here.

The Tbl entries are these as of now:

RecordsDoExist.png.bfcc67acc4a013cb01c80728f41b7b85.png

	<?php 
	//Required PHP Files. 
include 'config.php'; 
include 'header.php'; 
include 'account_header.php'; 
	?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta content="text/html; charset=ISO-8859-1" http-equiv=" content-type"> 
<title><?php echo "$site_name User $user Notices in $server_time time."; ?></title> 
</head> 
<body> 
<br> 
<p align="center"><span style="font-weight:bold;"><?php echo "$site_name User $user Notices in $server_time time."; ?></span></align> 
<br> 
<br> 
<?php 
if (!$conn) 
{ 
    $error = mysqli_connect_error(); 
    $errno = mysqli_connect_errno(); 
    print "$errno: $error\n"; 
    exit(); 
} 
else 
{ 
    if ($_GET["Result_SearchType"] == "Domain") 
    { 
        //Grabbing these: $_GET["Result_PageType"],$_GET["Result_Domain"]. 
        $first_param = $_GET["Result_PageType"]; 
        $second_param = $_GET["Result_Domain"]; 
        
        
        //$query = "SELECT * FROM notices"; 
    $query = "SELECT * FROM submissions_index WHERE page_type = '$first_param' AND domain = '$second_param'"; 
    echo "First Param: $first_param<br>"; 
    echo "Second Param: $second_param<br>"; 
    $result = mysqli_query($conn,$query); 
    $rows_num = mysqli_num_rows($result); 
    
    //Total Number of Pages records are spread-over. 
    $page_count = 10; 
    $page_size = ceil($rows_num / $page_count); 
    //Get the Page Number. Default is 1 (First Page). 
    $Result_PageNumber = $_GET["Result_PageNumber"]; 
    if ($Result_PageNumber == "") $Result_PageNumber = 1; 
        $offset = ($Result_PageNumber -1) * $page_size; 
        
        $query .= " limit {$offset},{$page_size}"; 
        $result = mysqli_query($conn,$query); 
    ?> 
    <table width="1500" border="0" cellpadding="5" cellspacing="2" bgcolor="#666666"> 
    <?php 
    if($rows_num) 
    { 
        printf("<b> %d Result Found ...</b>\n",$rows_num); ?><br> 
        <br> 
        <tr name="headings"> 
        <td bgcolor="#FFFFFF" name="column-heading_submission-number">Submission Number</td> 
        <td bgcolor="#FFFFFF" name="column-heading_logging-server-date-&-time">Date & Time in <?php $server_time ?></td> 
        <td bgcolor="FFFFFF"  name="column-heading_domain">Domain</td> 
        <td bgcolor="#FFFFFF" name="column-heading_page-type">Page Type</td> 
                <td bgcolor="#FFFFFF" name="column-heading_page">Page</td> 
        <td bgcolor="#FFFFFF" name="column-heading_page-title">Page Title</td> 
        <td bgcolor="#FFFFFF" name="column-heading_page-description">Page Description</td> 
        </tr> 
        <?php while($row = mysqli_fetch_array($result)) 
        { 
            ?> 
            <tr name="user-details"> 
            <td bgcolor="#FFFFFF" name="submission-number"><?php echo $row['id']; ?></td> 
            <td bgcolor="#FFFFFF" name="logging-server-date-&-time"><?php echo $row['date_and_time']; ?></td> 
            <td bgcolor="#FFFFFF" name="domain"><?php echo $row['domain']; ?></td> 
            <td bgcolor="#FFFFFF" name="page-type"><?php echo $row['page_type']; ?></td> 
            <td bgcolor="#FFFFFF" name="page"><?php echo $row['page']; ?></td> 
            <td bgcolor="#FFFFFF" name="page"><?php echo $row['title']; ?></td> 
            <td bgcolor="#FFFFFF" name="page"><?php echo $row['description']; ?></td>             
            </tr> 
            <?php 
        } 
        ?> 
        <tr name="pagination"> 
        <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
        <?php 
        if($rows_num <= $page_size) 
        { 
            echo "Page 1"; 
        } 
        else 
        { 
            $next = $_GET;
            for($i=1; $i <= $page_count; $i++) 
            { 
                $next["Result_PageNumber"] = $i; 
                //echo "<a href='links_stats_editing.php?", http_build_query($next), "'>{$i}</a> ";
                echo "<a href=\"{$_SERVER['PHP_SELF']}?", http_build_query($next), "'>{$i}</a> "; 
            } 
        } 
        ?> 
        </td> 
        </tr> 
        <?php 
    } 
    else 
    { 
        ?> 
        <tr> 
        <td bgcolor="#FFFFFF">No record found! Try another time.</td> 
        </tr> 
        <?php 
    } 
    ?> 
    </table> 
    <br> 
    <br> 
    <p align="center"><span style="font-weight:bold;"><?php echo "$site_name User $user Notices in $server_time time."; ?></span></align>
    <br> 
    <br> 
    </div> 
    <br> 
    </body> 
    </html>
	

 

I shortened the following code as much as possible before posting here as it has a lot of elseifs. I just turned one of the elseifs into an if and pasted it here so you don't get bogged down with all that lines of 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: $error\n"; 
    exit(); 
} 
else 
{     
    ?>
    <body bgcolor='blue'> 
    <?php     
    //Get the Page Number. Default is 1 (First Page). 
    $Result_PageNumber = $_GET["Result_PageNumber"]; 
    if ($Result_PageNumber == "") 
    { 
        $Result_PageNumber = 1; 
    } 
    
    $Result_LinksPerPage = $_GET["Result_LinksPerPage"]; 
    if ($Result_LinksPerPage == "") 
    { 
        $Result_LinksPerPage = 1; 
    } 
    
    $max_result = 100;     
    //$offset = ($Result_PageNumber*$Result_LinksPerPage)-$Result_LinksPerPage; 
    $offset = ($Result_PageNumber-1)*$Result_LinksPerPage; 
    if ($_GET["Result_SearchType"] == "Domain") 
    { 
        //Grabbing these: $_GET["Result_Domain"], $_GET["Result_PageType"]. 
        $first_param = $_GET["Result_PageType"]; echo "First Param: $first_param<br>"; //These are getting echoed
        $second_param = $_GET["Result_Domain"]; echo "Second Param: $second_param<br>"; //These are getting echoed
        $query_1 = "SELECT COUNT(*) FROM submissions_index WHERE page_type = ? AND domain = ? ORDER BY id LIMIT ? OFFSET ?"; 
        
        $stmt_1 = mysqli_prepare($conn,$query_1); 
        if(($stmt_1 = mysqli_prepare($conn,$query_1)) == false) {
        throw new Exception(mysqli_error($conn));
        } // NogDog's Error Code
        mysqli_stmt_bind_param($stmt_1,'ssii',$first_param,$second_param,$Result_LinksPerPage,$offset); 
        echo "Links Per Page: $Result_LinksPerPage<br>"; //These are getting echoed
        echo "Offset: $offset<br>"; //These are getting echoed
        if((mysqli_stmt_execute($stmt_1)) == false) {
        throw new Exception(mysqli_stmt_error($stmt_1));
        } // NogDog's Error Code
        mysqli_stmt_execute($stmt_1); 
        $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count); 
        echo "$matching_rows_count"; //THIS IS NOT GETTING ECHOED !!! WHY ?
        mysqli_stmt_fetch($stmt_1); 
        mysqli_stmt_free_result($stmt_1); 
        
        $total_pages = ceil($matching_rows_count/$Result_LinksPerPage); 
        $query_2 = "SELECT id,date_and_time,domain,page_type,page,title,description,anchor_text FROM submissions_index WHERE page_type = ? AND domain = ? ORDER BY id LIMIT ? OFFSET ?"; 
        $stmt_2 = mysqli_prepare($conn,$query_2); 
        mysqli_stmt_bind_param($stmt_2,'ssii',$first_param,$second_param,$Result_LinksPerPage,$offset); 
        mysqli_stmt_execute($stmt_2); //THIS LINE WAS MISSING
        $result_2 = mysqli_stmt_bind_result($stmt_2,$Result_Id,$Result_LinkSubmissionDateAndTime,$Result_Domain,$Result_PageType,$Result_Page,$Result_PageTitle,$Result_PageDescription,$Result_AnchorText); 
        mysqli_stmt_fetch($stmt_2); 
    } 
if(!$stmt_2) 
        { 
            ?> 
            <tr> 
            <td bgcolor="#FFFFFF">No record found! Try another time.</td> 
            </tr> 
            <?php 
        } 
        else 
        { 
            if(($offset+1)<=$max_result) 
            { 
                ?>
                <p align="left"> 
                <?php echo "<font color='white'><b>LINK SUBMISSION ID:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_Id</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>LINK SUBMISSION DATE & TIME:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_LinkSubmissionDateAndTime</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>DOMAIN:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_Domain</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>PAGE:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_Page</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>PAGE TYPE:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_PageType</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>PAGE TITLE:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_PageTitle</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>PAGE DESCRIPTION:</b></font>"; ?><br> 
                <?php echo "<font color='white'><i>$Result_PageDescription</i></font>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>PAGE SEARCH STATISTICS:</b></font>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> 
                <br> 
                <br> 
                <?php echo "<font color='white'><b>DOMAIN SEARCH STATISTICS:</b></font>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> 
                <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> 
                <br> 
                <br> 
                </align> 
                <?php 
                //Use this technique: http://php.net/manual/en/mysqli-stmt.fetch.php
                while(mysqli_stmt_fetch($stmt_2)) 
                { 
                    ?> 
                    <p align="left"> 
                    <?php echo "<font color='white'><b>LINK SUBMISSION ID:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_Id</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>LINK SUBMISSION DATE & TIME:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_LinkSubmissionDateAndTime</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>DOMAIN:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_Domain</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>PAGE:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_Page</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>PAGE TYPE:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_PageType</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>PAGE TITLE:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_PageTitle</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>PAGE DESCRIPTION:</b></font>"; ?><br> 
                    <?php echo "<font color='white'><i>$Result_PageDescription</i></font>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>PAGE SEARCH STATISTICS:</b></font>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Keywords&Result_PageType=$Result_PageType&Result_Page=$Result_Page&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> 
                    <br> 
                    <br> 
                    <?php echo "<font color='white'><b>DOMAIN SEARCH STATISTICS:</b></font>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Current&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='gold'><b>Current Visitor</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Last&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='silver'><b>Last Visitor</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Latest&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='bronze'><b>Latest Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Lost&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='grey'><b>Lost Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Unhappy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='yellow'><b>Unhappy Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Happy&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='green'><b>Happy Visitors</b></font></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=Competing&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='red'><b>Competing Visitors</font></b></a>"; ?><br> 
                    <?php echo "<a href=\"visits_stats.php?Result_StatsType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_VisitorType=All&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber=\"><font color='blue'><b>All Visitors</font></b></a>"; ?><br> 
                    <br> 
                    <br> 
                    </align> 
                    <?php 
                }
                ?> 
                <tr name="pagination"> 
                <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
                <?php  
                //if($offset<$max_result)                 
                if($Result_PageNumber<$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&Result_SearchType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber={$i}\"><font color='white'><b>{$i}</b></font></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&Result_SearchType=Domain&Result_PageType=$Result_PageType&Result_Domain=$Result_Domain&Result_LinksPerPage=$Result_LinksPerPage&Result_PageNumber={$i}\"><font color='white'><b>{$i}</b></font></a> "; 
                } 
                ?> 
                </td> 
                </tr> 
                <?php 
            } 
        } 
    ?>   
    </table>     
    <br> 
    <br> 
    <p align="center"><span style="font-weight:bold;"><?php echo "Search Result: <br>Searching for ...\"$second_param\" <br>Page Type: $first_param<br> Matches: $matching_rows_count <br>"; ?></span></align> 
    <br> 
    </div> 
    <br> 
    </body> 
    </html>
	

Error reporting in one of the included files:

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

Now, who's gonna show me what to ditch ?

Link to comment
Share on other sites

separation of concerns. if you use his programming practice, converting the database specific code from using a non-prepared query to a prepared one, or even converting it to use the php PDO extension, is easy, because all the database specific code, that knows how to query for and retrieve data, would be groped together and be located before the start of the html document. 

the way to implement this separation of concerns, after you rearrange the code to get the database specific code out of the html document, is to simply fetch the data from any data retrieval query into an appropriately named php variable(s), then simply use the variables(s) (test if it's empty or not or loop over it) in the html document.

once you do this, all you have to do when converting and testing the database specific code is make sure you produce the same data in the php variable(s). you won't have to touch any of the code in the html document.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.