![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
![]() I've been searching the web for basic php/mysql pagination tutorials to learn from since my book didn't cover this and having some problems.
Here's one that I'd like to learn from but it doesn't explain how to display the results on each page. After reading other pagination tutorials, I added a while loop and another query. Here's the link with source code, however I had to make some changes to make it work with mysqli: http://www.tyleringram.com/blog/basi...ation-tutorial Here's the while loop I added before the pages get echoed: Code:
$max = 'limit ' .($page - 1) * $LIMIT .',' .$LIMIT; $data_p = "SELECT * FROM model $max"; $result_2 = $db->query($data_p); while ($list = $result_2->fetch_assoc()) { // echo data echo $list['id'] . " : " . $list['name'] . "<br />"; } The url output appears like this: http://www.domain.com/2 http://www.domain.com/3 http://www.domain.com/4 etc..... |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 | |
Confirmed User
Industry Role:
Join Date: May 2003
Posts: 3,765
|
need to let it know which page you're on:
Quote:
__________________
flexx [dot] aeon [at] gmail |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Too lazy to set a custom title
Industry Role:
Join Date: Sep 2005
Location: Springfield
Posts: 13,826
|
Quote:
but he must use mod_rewrite to get it... better idea is something like site.com/page/3 or site.com/page-3 both must include mor_rewrite rule if need more help hit me up http://www.awmzone.com/services
__________________
Make a bank with Chaturbate - the best selling webcam program ![]() ![]() ![]() Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!! PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email: ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: May 2011
Location: San Diego
Posts: 328
|
your echo is wrong:
Code:
echo "<a href=\"".$_SERVER['PHP_SELF']."/?page={$i}\">{$i}</a>"; you don't want the / in there ![]() try: Code:
echo "<a href=\"".$_SERVER['PHP_SELF']."?page={$i}\">{$i}</a>"; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
Quote:
Right now when I clicked on page 2 or 3 I see the url link in the address bar but the results don't change.. still displays the query results from page 1. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: May 2011
Location: San Diego
Posts: 328
|
Code:
if (!$_GET['page'] && !ctype_digit($_GET['page'])) { throw new Exception('page number must be digit'); } $page = $_GET['page']; $limit = 5; $max = 'limit ' .($page - 1) * $limit .',' .$limit; $data_p = "SELECT * FROM testtable $max"; $result_2 = mysql_query($data_p); while ($list = mysql_fetch_assoc($result_2)) { // echo data echo $list['random'] . "<br />"; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
That's basically what I have but it's still not working. Here's my complete code:
Code:
<?php if (!$_GET['page'] && !ctype_digit($_GET['page'])) { throw new Exception('page number must be digit'); } // 5 Entries Per Page $LIMIT = 5; if (isset($_GET['page'])) { // Get Current page from URL $page = $_GET['page']; } if ($page <= 0) { // Page is less than 0 then set it to 1 $page = 1; } else { // URL does not show the page set it to 1 $page = 1; } // Create MySQL Query String include("../includes/connect.php"); // This is for your MySQL Query to limit the entries per page $LimitValue = $page * $LIMIT - ($LIMIT); $strqry = "SELECT id, name from model"; $result = $db->query($strqry); // $query = mysql_query($strqry) or die("MySQL Error: <br /> {$strqry} <br />", mysql_error()); // Get number of rows returned $TOTALROWS = $result->num_rows; // Figure out how many pages there should be based on your $LIMIT $NumOfPages = $TOTALROWS / $LIMIT; // This is for your MySQL Query to limit the entries per page // $LimitValue = $page * $LIMIT - ($LIMIT); $max = 'limit ' .($page - 1) * $LIMIT .',' .$LIMIT; $data_p = "SELECT * FROM model $max"; $result_2 = $db->query($data_p); while ($list = $result_2->fetch_assoc()) { // echo data echo $list['id'] . " : " . $list['name'] . "<br />"; } echo "<div id=\"paginating\" align=\"left\">Pages:"; // Check to make sure we’re not on page 1 or Total number of pages is not 1 if ($page == ceil($NumOfPages) && $page != 1) { for($i = 1; $i <= ceil($NumOfPages)-1; $i++) { // Loop through the number of total pages if($i > 0) { // if $i greater than 0 display it as a hyperlink echo "<a href=\"".$_SERVER['PHP_SELF']."?page={$i}\">{$i}</a>"; } } } if ($page == ceil($NumOfPages) ) { $startPage = $page; } else { $startPage = 1; } for ($i = $startPage; $i <= $page+6; $i++) { // Display first 7 pages if ($i <= ceil($NumOfPages)) { // $page is not the last page if($i == $page) { // $page is current page echo " [{$i}] "; } else { // Not the current page Hyperlink them echo "<a href=\"".$_SERVER['PHP_SELF']."?page={$i}\">{$i}</a> "; } } } echo "</div>"; echo "<p>Number of results found: ".$TOTALROWS."</p>"; ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Industry Role:
Join Date: May 2011
Location: San Diego
Posts: 328
|
Code:
if ($page <= 0) { // Page is less than 0 then set it to 1 $page = 1; } else { // URL does not show the page set it to 1 $page = 1; } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | ||
Confirmed User
Industry Role:
Join Date: May 2003
Posts: 3,765
|
i didn't read through the rest of the code past this part:
Quote:
Quote:
__________________
flexx [dot] aeon [at] gmail |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
That worked, thanks!!!
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
Sorry one more question about this....
I'm trying to display to results by RAND() and have added the following to the top of the code: Code:
session_start(); $rand = $_SESSION['rand']; if (empty($rand)) { srand((float)microtime()*1000000); $rand = "0.".rand(); $_SESSION['rand'] = $rand; } How can I have it so when you refresh the page or revisit it randomizes the results but doesn't again when you click on page 2, page 3, etc? I tried adding in the following in a few places but doesn't seem to do anything: Code:
if(isset($_SESSION['rand'])) unset($_SESSION['rand']); Code:
$data_p = "SELECT * FROM model WHERE status = 'Active' ORDER BY RAND($rand) $max"; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Quote:
Code:
$page = (isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1); $page = ($page < 1 ? 1 : $page); session_start(); $rand = (isset($_SESSION['rand']) ? intval($_SESSION['rand']) : 0); if( $rand < 1 || $page < 2 ){ $rand = mt_rand(100000, 999999); $_SESSION['rand'] = $rand; } session_write_close(); |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
That didn't seem to work Tempest. Anymore ideas?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
By the way, I'm using php includes and it may be the problem.
File1 has the php session and include codes. File2 has the pagination code. File3 is a template file. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Confirmed User
Industry Role:
Join Date: Feb 2004
Location: Vancouver
Posts: 1,821
|
__________________
I could give two shits wether you read this sig or not. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Too lazy to set a custom title
Join Date: Jan 2002
Location: Holland
Posts: 9,870
|
www.stackoverflow.com is your best shot
__________________
Don't let greediness blur your vision | You gotta let some shit slide icq - 441-456-888 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
I just tested the code I posted and it works perfectly.. i.e. page <= 1 generates a new random number and any other page uses the number that's stored in the session.
So the only thing I can think of is that your session isn't getting set properly. Make sure there is NO output before the session is opened, variables saved etc. Check the source of the page and see if there's any blank lines at the top for example. Turn on error reporting to see if any errors are getting thrown. Put this right at the very start of the script. Code:
ini_set('display_errors', 1); error_reporting(E_ALL); |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
All these people offering advice and nobody points out to you that you have a giant gaping massive security hole... never, Never, NEVER use GET or POST variables right in a fucking SQL statement...
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Really? Care to point out where that is.. Unless I missed it in one of the posts, in almost all cases the only GET/POST variable used (page) is qualified in some way ahead of time.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 | |
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
|
Quote:
You mean something like this ? PHP Code:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 | |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
Quote:
'; DROP DATABASE 'XXXXX Byebye data... SQL injection FTL. Check out http://us.php.net/manual/en/mysqli.r...ape-string.php
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 | |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
Quote:
Code:
$page = mysql_escape_string($_GET['page']);
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
See anything wrong with this code?
Code:
<?php session_start(); $rand = (isset($_SESSION['rand']) ? intval($_SESSION['rand']) : 0); if( $rand < 1 || $page < 2 ){ $rand = mt_rand(100000, 999999); $_SESSION['rand'] = $rand; } session_write_close(); $side_a = "includes/side-a.php"; $content = "includes/content.php"; include("template.php"); ?> echo "rand = ". $_SESSION['rand']; and each page has a different $rand value so it's not being saved... is there something wrong with the way I include files? I didn't find any blank lines in the files or output. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 | |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
|
Quote:
PHP Code:
and it doesn't work no matter what. Only what i noticed is how this causing query not to execute. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 | |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
Quote:
Wait wait wait... Are you saying you don't think SQL injections are possible with uncleaned GET/POST values?
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 |
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
|
No i saying how i was not able to find proper combination to execute sql injection and i am sure how there is proper combination which will do the job.I still agree how leaving unprotected GET/POST value is huge security risk and should be protected no matter what.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 | |
Confirmed User
Industry Role:
Join Date: Dec 2004
Location: Denver
Posts: 6,559
|
Quote:
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
Don't close the session if you want access to the $_SESSION vars... You actually don't ever need to close the session for any normal logic, it happens automatically. The only time you really need to close it manually is if you need to have multiple requests from the same user modify the session data...
Let's say you're doing a large file upload and you want to track progress. Whatever PHP process is being held open by the file upload, you would want to close out the session in that request so that additional requests (checking the progress) would have access to the updated session values...
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#34 |
Confirmed User
Join Date: Jun 2009
Location: Asheville, NC
Posts: 2,277
|
In regards to SQL injection...
PHP now (as a safety measure) will not run multiple queries in the same SQL request. That doesn't mean you can't modify a single query to do other things though...
__________________
ICQ: 258-202-811 | Email: eric{at}bestxxxporn.com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#35 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
I just changed $strqry and $data_p and now when I click on page 2 it's showing 0 results.
old queries: Code:
$strqry = "SELECT id from model WHERE status = 'Active' "; $data_p = "SELECT * FROM model WHERE status = 'Active' ORDER BY RAND($rand) $max"; Code:
$strqry = "SELECT DISTINCT model.id from model INNER JOIN model_in_city ON (model_in_city.model_id = model.id) INNER JOIN city ON (city.city_id = model_in_city.city_id) INNER JOIN province on (city.province_id = province.id) WHERE province.name = '$region' AND model.status = 'Active' "; $data_p = "SELECT DISTINCT(model.id), model.thumbnail, model.name, model.location FROM model INNER JOIN model_in_city ON (model_in_city.model_id = model.id) INNER JOIN city ON (city.city_id = model_in_city.city_id) INNER JOIN province on (city.province_id = province.id) WHERE province.name = '$region' AND model.status = 'Active' ORDER BY RAND($rand) $max"; Post #8 has the complete code: https://gfy.com/showpost.php?p=18519612&postcount=8 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#36 |
So Fucking Banned
Industry Role:
Join Date: May 2009
Location: ΠπΠ
Posts: 2,419
|
pagination
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#37 |
Confirmed User
Industry Role:
Join Date: Aug 2003
Location: Canada
Posts: 2,310
|
Any ideas?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#38 |
Too lazy to set a custom title
Join Date: Jan 2002
Location: Holland
Posts: 9,870
|
stackoverflow.com , give it a try
__________________
Don't let greediness blur your vision | You gotta let some shit slide icq - 441-456-888 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#39 |
Confirmed User
Join Date: Oct 2002
Posts: 3,745
|
Because of the S in SQL, you can run two statements in one. Just inject a subquery, in other words put your malicious code in parentheses.
__________________
For historical display only. This information is not current: support@bettercgi.com ICQ 7208627 Strongbox - The next generation in site security Throttlebox - The next generation in bandwidth control Clonebox - Backup and disaster recovery on steroids |
![]() |
![]() ![]() ![]() ![]() ![]() |