Jump to content

Why Records Do Not Get Pulled ?


phpsane

Recommended Posts

Php Folks,

This is a Pagination Page Script.

This Url is supposed to pull some data from the mysql tbl. 
http://localhost/test/links_stats_editing.php?Result_SearchType=Domain&Result_PageType=Information20%Page&Result_Domain=go2.com&Result_PageNumber=

 

Why am I getting echoed: No record found! Try another time.

When the following records exist:

RecordsDoExist.png

 

	<?php 
	//Required PHP Files. 
include 'config.php'; 
include 'header.php'; 
include 'account_header.php'; 
	?> 
<!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 "$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 submissions_index WHERE page_type = '$first_param' AND domain = '$second_param'"; 
    echo "First Param: $first_param<br>"; //gets echoed
    echo "Second Param: $second_param<br>"; /gets echoed
    $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 
        { 
            for($i=1;$i<=$page_count;$i++) 
            echo "<a href=\"{$_SERVER['PHP_SELF']}?Result_PageNumber={$i}\">{$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>
	

 

Edited by phpsane
Link to comment
Share on other sites

Is that the actual URL? You copied and pasted it here?

"Information20%Page" is malformed. Should be "Information%20Page".

Plus, your navigation links won't work: you need to be using &s when you add the page number, not ?s. But if you do then each page's URL will get longer and longer as you keep adding page numbers in. A better way is

$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> ";
}

 

  • Like 1
Link to comment
Share on other sites

11 hours ago, requinix said:

Is that the actual URL? You copied and pasted it here?

"Information20%Page" is malformed. Should be "Information%20Page".

Plus, your navigation links won't work: you need to be using &s when you add the page number, not ?s. But if you do then each page's URL will get longer and longer as you keep adding page numbers in. A better way is


$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> ";
}

 

Thank you Requinix!

Yes, I typed that 20% on my browser. Then copied it here. Thank you for bringing it to my attention.

Few questions.

1. I did not know you can have just "$_GET" by itself. I thought it always has to be something like this: $_GET["Result_SearchType"].

So, what is the difference between the 2 types and why use this one over the other and when and why use that one over this one and when ?

2. Never came across http_build_query. Researching now:

http://php.net/manual/en/function.http-build-query.php

But, I hate the manual. Too complicated. Do you have any better tutorial link for the beginner to get to grips with it ?

3. I see the Pagination showing 10 pages. Results are shown only on 2 pages because I set it to show 1 result per page and there is only 2 matching rows.

And so, how do I get it to not show the other extra pages in the Pagination section ? In our case, only pages 1 & 2 should be shown since the other pages would show blank with no results.

Your code now shows: Next 12345678910.

I want it to show: Next 12.

Do you mind showing a sample code so the extra pages aren't shown? I will try then creating a reverse order so the last page with the result will show something like this:

Previous 21

I've done this before but like this:

	<tr name="pagination"> 
                <td colspan="10" bgcolor="#FFFFFF"> Result Pages: 
                <?php              
                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> 
	

The reversion worked in the past. But now it does not. I grabbed the above code from another one of my projects just to show you how I been doing it.

4. Can you find any errors on it ?

 

Once again thanks for the sample code. I will not just copy & paste but try learning the functions you used. That https_build_query is something new I am now getting a chance to get introduced to it and learn it. Thanks. :)

 

 

Link to comment
Share on other sites

2 minutes ago, phpsane said:

1. I did not know you can have just "$_GET" by itself. I thought it always has to be something like this: $_GET["Result_SearchType"].

So, what is the difference between the 2 types and why use this one over the other and when and why use that one over this one and when ?

$_GET is a variable. An array. It happens to be created by PHP and available globally, but it's still an array and works just like other arrays.

2 minutes ago, phpsane said:

2. Never came across http_build_query. Researching now:

http://php.net/manual/en/function.http-build-query.php

But, I hate the manual. Too complicated. Do you have any better tutorial link for the beginner to get to grips with it ?

The manual isn't a tutorial. It's a reference. If you want a tutorial then you'll have to search around for a tutorial that covers the subjects you want and presents it in a way you like.

2 minutes ago, phpsane said:

3. I see the Pagination showing 10 pages. Results are shown only on 2 pages because I set it to show 1 result per page and there is only 2 matching rows.

And so, how do I get it to not show the other extra pages in the Pagination section ? In our case, only pages 1 & 2 should be shown since the other pages would show blank with no results.

Your code now shows: Next 12345678910.

I want it to show: Next 12.

Don't show a fixed number of pages with a variable number of results on each. That's weird. Literally nobody does that.

Fixed number of results per page, like 10, variable number of pages. Then your example will only have one page.

Link to comment
Share on other sites

1 hour ago, requinix said:

$_GET is a variable. An array. It happens to be created by PHP and available globally, but it's still an array and works just like other arrays.

The manual isn't a tutorial. It's a reference. If you want a tutorial then you'll have to search around for a tutorial that covers the subjects you want and presents it in a way you like.

Don't show a fixed number of pages with a variable number of results on each. That's weird. Literally nobody does that.

Fixed number of results per page, like 10, variable number of pages. Then your example will only have one page.

I'm not sure if you understood my motive. Not trying to have a fixed number of pages with variable number of results on each page.

I'm trying to show a variable number of links on the pages. For example, if you google then you know it shows you 10 results per page.

Now, if there are only 30 results then I don't want 10 pages showing up on the pagination section like this:

Next 12345678910.

Reason why I do not want this is because if the results are on the first 3 pages then no good listing links to the other 7 pages. And so, in this case, it would be shown like this:

Pages: 123

No links to the 4th page and beyond.

If the query yields 45 results and there are 10 results per page (fixed number of results per page), then the results would be 5 pages. And so, the pagination section on each page from page 1 to 4 would show the page links like this:

Pages:12345.

The 5th page (last page in this example) would show the page links in reverse order like this:

Pages 4321.

That way, from the final page, you can clickover and go backwards to the other pages.

So how to do all that ? Forget the final page showing page links in reverse order as I'll manage to do that. But, I need help in the other part where the fixed number of results per page are spreadover variable number of pages.

 

Thanks!

Edited by phpsane
Link to comment
Share on other sites

20 minutes ago, Barand said:

You get pages 1 2 3 ... 10 because you are defining the number of pages to be 10.

As you have been told many times, here for example, you need an initial query to count the number of results you will get, then calculate the number of pages from this count.

Yeah. I did not see "10" mentioned on Requinix's code and so looked above in my supposed code and found this:

	$page_count = 10; 
	

If you really must know. This is not my code. Found it online 2-3yrs back. And then tried converting it to PREP STMNT and are struggling. I have a thread open here somewhere on it. i will look back on it now and see if I can heed Mac Guyver's advice. He gave a long list and I got spooked and left it at that. Now, gonna get back at it and if I get stuck then I got you wonderful guys to help me out.

Oh btw, I did mention just now that, the code you see on my original post here is not my own. But that other thread that I mentioned which lists my code that is an attempt to turn it into PREP STMT is 100% all my code. Well, atleast I'm trying something by myself without 100% copying others. Right ?

@requinix, Where is that thread of mine where I attempt building a Pagination with PREP STMT ? I can't find it here:

https://forums.phpfreaks.com/profile/204793-phpsane/

You know, the one Mac Guyver gave a long list of corrections. I need to get back on it and work on it. Can't be opening another duplicate thread.

Edited by phpsane
Link to comment
Share on other sites

Requinix,

 

Why can't I login to my Devshed account ? I need to get back there again. Guys over there were patient. I don't want to be prowling here unless it is really necessary. Mac Guyver's short tempered and he'll ban me again here. And Ginerjm is short tempered here too but he is really patient with me on other forums when I use different Userrnames than here. ;)

I only want to drop by here if I fail to get answers on any other forum like the Dev Shed one. So fixed my issue in my account over there so I can get back again at Dev Shed. My password no longer works there.

Link to comment
Share on other sites

I get 'short-tempered' with people who refuse to listen to the suggestions that they receive.  Especially those who think that the manual is too complicated.  You are posting here in order to learn, aren't you?  Well, reading and comprehending any manual is part of that learning experience.  If you cannot take the time to understand the complexities of coding, perhaps you need to focus on something else.

I also get frustrated with people who post other's code - not their own.  They get code from one side, answers from another side and consider it "their own".  Jeez!

And I do recognize this name of yours. 

  • Haha 1
  • Great Answer 1
Link to comment
Share on other sites

2 minutes ago, ginerjm said:

I get 'short-tempered' with people who refuse to listen to the suggestions that they receive.  Especially those who think that the manual is too complicated.  You are posting here in order to learn, aren't you?  Well, reading and comprehending any manual is part of that learning experience.  If you cannot take the time to understand the complexities of coding, perhaps you need to focus on something else.

I also get frustrated with people who post other's code - not their own.  They get code from one side, answers from another side and consider it "their own".  Jeez!

And I do recognize this name of yours. 

The php manual is a reference and not a tutorial guide. Many members in many forums warned me against tryign to learn from it. I nearly quit php twice due to getting frustrated from it. At the end, sites like tutorialspoint.com, tutorialrepublic.com, etc. made me think twice before quitting.

I ain't gonna quit now. Came this long. Nearly 2yrs.

And no. I do not think others' codes are mine. If I did, I would not mention that the code you see here is not mine. Look at the code again and then check this one out:

http://forums.devshed.com/php-development/980539-mixed-pagination-mystery-post2985323.html#post2985323

Latter one is my own code with a little help. It is an attempt to convert another's pagination code to PREP STMNT.

Link to comment
Share on other sites

What is PREP STMNT?  Is it your own abbreviation for something that EVERYONE else calls 'using a prepared statement'?

Using your own shorthand to describe what are very specific things in this business is a sure way to get lost and to receive incorrect advice since people may not understand your meanings.  I suggest using proper terminology for everything

  • Like 1
Link to comment
Share on other sites

Requinix,

 

I was just playing around with your code. Remember this code of your's ...

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

It shows pagination like this:

Result Pages: 1 2 3 4 5 6 7 8 9 10

I'm not complaining. I beginning to like it.

But, I thought, if I ever change the file name from then I do not want to be rewriting the file name.

And so, I changed your code from this:

 

	 echo "<a href='links_stats_editing.php?", http_build_query($next), "'>{$i}</a> ";
	

to this: 

 

	echo "<a href=\"{$_SERVER['PHP_SELF']}?", http_build_query($next), "'>{$i}</a> "; 
	

And I now see pagination like the following which I do not like. Why the page numbers getting incremented by 2 ? 

Result Pages: 2 4 6 8 10

I did not dbl the increment here. Just changed this:

"<a href='links_stats_editing.php?"

to this:

"<a href=\"{$_SERVER['PHP_SELF']}?"

 

That is all.

Strange!

 

 

 

 

 

Edited by phpsane
Link to comment
Share on other sites

Have you looked at the URLs your code is generating? PHP_SELF is much more than just the filename. And you're mixing quotes.

If you're scared about having to change a filename next time you copy and paste this code somewhere then use basename(__FILE__).

echo "<a href=\"", basename(__FILE__), "?", http_build_query($next), "\">{$i}</a>";

 

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.