xfezz Posted October 30, 2006 Share Posted October 30, 2006 Im sure ill be kicking myself for asking this. I know it has to do with the offset, but I cant quite put my finger on it on how to code it. I came up with this, I know its not correct since it doesnt give back the right results all the time.[code]$min_num = $offset+ 1;$max_num = ($min_num + $max_results)-1;[/code]where max_results is the limit to how many results per page.max_num doesnt display correctly if the total entries in the database is an odd number. but min_num displays the correct value each and every time. Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/ Share on other sites More sharing options...
ignace Posted October 30, 2006 Share Posted October 30, 2006 oh ok, i will look into the problem and post the correct code Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116603 Share on other sites More sharing options...
xfezz Posted October 30, 2006 Author Share Posted October 30, 2006 Thanks for the reply I probably should of been more clear. Im not looking to display the number of pages, but the number of entries in the database for the corresponding page that the user is currently on. Pretty much like how amazon.com has their results set up.[url=http://www.amazon.com/s/ref=nb_ss_gw/102-6043809-7736157?url=search-alias%3Dstripbooks&field-keywords=php&Go.x=0&Go.y=0&Go=Go]http://www.amazon.com/s/ref=nb_ss_gw/102-6043809-7736157?url=search-alias%3Dstripbooks&field-keywords=php&Go.x=0&Go.y=0&Go=Go[/url]I think that will work Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116607 Share on other sites More sharing options...
.josh Posted October 30, 2006 Share Posted October 30, 2006 you mean the "Showing 1 - 12 of 11784 Results" part? Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116615 Share on other sites More sharing options...
xfezz Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=Crayon Violent link=topic=113200.msg459844#msg459844 date=1162198478]you mean the "Showing 1 - 12 of 11784 Results" part? [/quote]yep Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116619 Share on other sites More sharing options...
.josh Posted October 30, 2006 Share Posted October 30, 2006 [code]$sql = "select * from table order by $sortby limit $from, $max_results";$getlist = mysql_query($sql, $conn) or die(mysql_error());$sql = "select count(*) as num from table";$getcount = mysql_query($sql, $conn) or die(mysql_error());$total_results = mysql_result($getcount, 0) or die(mysql_error());$fr = $from + 1;$to = $from + mysql_num_rows($getlist);echo "showing $fr - $to of $total_results results";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116620 Share on other sites More sharing options...
xfezz Posted October 30, 2006 Author Share Posted October 30, 2006 hmm i get an error on line 40 of my code. which is the $getlist = mysql_query($sql, $conn) or die(mysql_error()); statement[code]$sql = mysql_query("SELECT * FROM articles ORDER BY id DESC LIMIT $from, $max_results");$getlist = mysql_query($sql, $conn) or die(mysql_error());[/code]Warning: mysql_query(): supplied argument is not a valid MySQL-Link resourceedit: changed the above to this. and I still get the error[code]$sql = "SELECT * FROM articles ORDER BY id DESC LIMIT $from, $max_results";$getlist = mysql_query($sql, $conn) or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116622 Share on other sites More sharing options...
.josh Posted October 30, 2006 Share Posted October 30, 2006 how did you connect to the database? my code assumes the following:$conn = mysql_connect('localhost','username','password') or die(mysql_error());and then the $getlist query uses the optional 2nd argument to specify the connection. Either change $conn to your connection var or if you did assign the connection to a var, simply remove the $conn argument from the mysql_query:$getlist = mysql_query($sql) or die(mysql_error());edit: also, you need to re-look at my code. I have the query seperated from the function call. The way you listed it, you have the query string combined with the function call, which returns and assigns the result source to $sql. Then you turn around and try to use that result source in your $getlist query function call, instead of a query string. Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116624 Share on other sites More sharing options...
xfezz Posted October 30, 2006 Author Share Posted October 30, 2006 I connect to the database with the following[code]//set server and database parameters $user_name = "root"; $password = "some really cool password"; $database = "article_db"; $server = "localhost"; //make connection to database $db_handle = mysql_connect($server, $user_name, $password)or die("cannot connect to server"); $db_found = mysql_select_db($database, $db_handle)or die("cannot select database"); [/code]I removed the $conn from the query and now it doesnt like my while loop.Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Apache\htdocs\port\admin_article_selec.php on line 43[code]while($row = mysql_fetch_array($sql)){ // Build your formatted results here. $now_format = $row['article_date']; $new_format = date('F d, Y',strtotime($now_format)); // transform the date echo "<div id=\"article_date\">". $new_format ."</div> \n"; // prints out: date in following format October 20, 2006 echo "<div id=\"article_chk\">"."<input type=\"checkbox\" name=\"del_select[]\" value=\"$row[id]\" />"."</div>"."<br>\n"; $row['message']=nl2br($row['message']); echo "<div id=\"article_body\">" .$row['message'] ."</div>\n"; echo $row['title'];}[/code]Fix one thing and then cause another problem. 8) ill look more into it tomorrow. There may be something im missing. As for now im off for bed. thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116627 Share on other sites More sharing options...
.josh Posted October 30, 2006 Share Posted October 30, 2006 [code]$sql = "SELECT * FROM articles ORDER BY id DESC LIMIT $from, $max_results";$getlist = mysql_query($sql, $db_handle) or die(mysql_error());..while($row = mysql_fetch_array($getlist)){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116630 Share on other sites More sharing options...
xfezz Posted October 30, 2006 Author Share Posted October 30, 2006 [quote author=Crayon Violent link=topic=113200.msg459859#msg459859 date=1162201226][code]$sql = "SELECT * FROM articles ORDER BY id DESC LIMIT $from, $max_results";$getlist = mysql_query($sql, $db_handle) or die(mysql_error());..while($row = mysql_fetch_array($getlist)){[/code][/quote]Yep I woke up and that was the first thing I changed. I suppose I was too tired to catch that early this morning. Its working now. Thanks a bunch Quote Link to comment https://forums.phpfreaks.com/topic/25557-simple-pagination-question-displaying-1-3-of-5-results/#findComment-116862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.