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;} } ?> Quote Link to comment 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); Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 25, 2007 Share Posted July 25, 2007 can we see your code now Quote Link to comment 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;} } ?> Quote Link to comment Share on other sites More sharing options...
Foser Posted July 25, 2007 Author Share Posted July 25, 2007 fixed it. Quote Link to comment 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.