Foser Posted July 24, 2007 Share Posted July 24, 2007 Nothing executes I'm trying to find why... I'm trying to make my own simple pagination program. heres the script: index.php <?php mysql_connect(localhost, root, password) or die(mysql_error()); mysql_select_db(tutorial1) or die(mysql_error()); include_once('function.php'); if (!isset($_GET['PAGE'])){ $getpage = 1;} else { $getpage = $_GET['PAGE'];} max_ammount($getpage,2); next_number($getpage); $query1 = mysql_query("SELECT * FROM pagination ORDER BY id"); while (mysql_num_rows($query1) <= $max_value && mysql_num_rows($query1) > $min_value ){ echo "ID Number: {$query['id']}<br>Name: {$query['name']}<br>Age: {$query['age']}<br>Referer: {$query['referer']}<br>-----------------------------------------------------<br>"; } ?> function.php <?php function max_ammount($getpage,$maxammount){ if ($getpage <= 1){ $max_value = 1; return $max_value;} else { $max_value = $getpage * $maxammount; return $max_value;} } function next_number($getpage){ if ($getpage <= 1){ $min_value = 0; return $min_value;} else { $get_1 = $getpage. + 1; $min_value = $get_1. + 2; return $min_value;} } ?> Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/ Share on other sites More sharing options...
btherl Posted July 24, 2007 Share Posted July 24, 2007 When a function returns a value, you need to set that value to a variable. For example: $max_value = max_ammount($getpage,2); $min_value = next_number($getpage); Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-305975 Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 i dont see you use the limit clause? Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-305978 Share on other sites More sharing options...
Foser Posted July 24, 2007 Author Share Posted July 24, 2007 i dont see you use the limit clause? Could you give an example of limit clause? Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-305984 Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 mysql_query("SELECT * FROM pagination ORDER BY id limit $min_value ,$max_value "); thats how paging work ooops glad thorpe dont see my post lol or else he will say stop posting one liner explanation lol Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-305986 Share on other sites More sharing options...
btherl Posted July 24, 2007 Share Posted July 24, 2007 $num = $max_value -$min_value + 1; $query1 = mysql_query("SELECT * FROM pagination ORDER BY id LIMIT $min_value, $num"); while ($row = mysql_fetch_assoc($query1)){ echo "ID Number: {$row['id']}<br>Name: {$row['name']}<br>Age: {$row['age']}<br>Referer: {$row['referer']}<br>-----------------------------------------------------<br>"; } Give that a try and let us know how it goes. My mysql syntax is a bit rusty, as i'm a postgres user. Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-305992 Share on other sites More sharing options...
Foser Posted July 25, 2007 Author Share Posted July 25, 2007 Works but I think im limiting too much since it's only displayed 1. Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-306862 Share on other sites More sharing options...
teng84 Posted July 25, 2007 Share Posted July 25, 2007 can we see your code now Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-306870 Share on other sites More sharing options...
Foser Posted July 25, 2007 Author Share Posted July 25, 2007 <?php mysql_connect(localhost, root, password) or die(mysql_error()); mysql_select_db(tutorial1) or die(mysql_error()); include_once('function.php'); if (!isset($_GET['PAGE'])){ $getpage = 0;} else { $getpage = $_GET['PAGE'];} $max_value = max_ammount($getpage,2); $min_value = next_number($getpage); $query1 = mysql_query("SELECT * FROM pagination ORDER BY id LIMIT $min_value , $max_value"); $query2 = mysql_query("SELECT * FROM pagination ORDER BY id"); while ($row_info = mysql_fetch_assoc($query1) ){ echo "ID Number: {$row_info['id']}<br>Name: {$row_info['name']}<br>Age: {$row_info['age']}<br>Referer: {$row_info['referer']}<br>-----------------------------------------------------<br>"; } if (mysql_num_rows($query2) > $max_value) { echo "<br>Next"; } ?> functions: <?php function max_ammount($getpage,$maxammount){ if ($getpage <= 1){ $max_value = 1; return $max_value;} else { $max_value = $getpage * $maxammount; return $max_value;} } function next_number($getpage){ if ($getpage <= 1){ $min_value = 0; return $min_value;} else { $get_1 = $getpage. + 1; $min_value = $get_1. + 2; return $min_value;} } ?> Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-306882 Share on other sites More sharing options...
Foser Posted July 25, 2007 Author Share Posted July 25, 2007 fixed it. Link to comment https://forums.phpfreaks.com/topic/61474-solved-pagination-script-whats-wrong-with-it/#findComment-306888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.