doforumda Posted March 18, 2010 Share Posted March 18, 2010 hi I create a script for pagination which works fine. Now what i want to do is to make a function of it so when i need it for any script i ll call that function so it ll work. I want to use function not classes. Here is the problem when i make a function of it then it displays this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pagination\function.php on line 9 here is my index.php include("function.php"); $connect = mysql_connect("localhost","user","pass"); $db = mysql_select_db("pagination"); //max number of posts to display per page. $per_page = 10; //get start variable. @$start = $_GET["start"]; $recordCount = mysql_num_rows(mysql_query("SELECT * FROM data")); $getData = mysql_query("SELECT * FROM data LIMIT $start, $per_page"); pagination($recordCount,$getData,$start,$per_page); here is my function.php <?php function pagination($record_count,$get_data,$start,$per_page) { $max_pages = $record_count / $per_page; if(!$start) $start = 0; //display the data. while($row = mysql_fetch_assoc($get_data)) { $name = $row["name"]; echo $name."<br>"; } //naviagtion here //setup previous and next variables. $prev = $start - $per_page; $next = $start + $per_page; //show prev button. if(!($start<=0)) { ?> <a href='index.php?start=<?php echo $prev; ?>'>Previous</a> <?php } //show page numbers. //set variable for first page. $i = 1; for($x=0; $x<$record_count; $x = $x + $per_page) { if($start != $x) { ?> <a href="index.php?start=<?php echo $x; ?>"><?php echo $i; ?></a> <?php } else { ?> <a href="index.php?start=<?php echo $x; ?>"><b><?php echo $i; ?></b></a> <?php } $i++; } //show next button if(!($start>=$record_count-$per_page)) { ?> <a href='index.php?start=<?php echo $next; ?>'>Next</a> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/195646-pagination-help/ Share on other sites More sharing options...
scvinodkumar Posted March 18, 2010 Share Posted March 18, 2010 Normally, as per ur coding, u will get this error because of query problem i think. try like this, by replacing the line @$start = $_GET["start"]; $start = 0 if($_GET["start"]!='') $start = $_GET["start"]; Link to comment https://forums.phpfreaks.com/topic/195646-pagination-help/#findComment-1027962 Share on other sites More sharing options...
doforumda Posted March 18, 2010 Author Share Posted March 18, 2010 scvinodkumar i did but the same error <?php function pagination($record_count,$get_data,$start,$per_page) { $max_pages = $record_count / $per_page; $start = 0; if(@$_GET["start"]!='') $start = $_GET["start"]; //display the data. while($row = mysql_fetch_assoc($get_data)) { $name = $row["name"]; echo $name."<br>"; } //naviagtion here //setup previous and next variables. $prev = $start - $per_page; $next = $start + $per_page; //show prev button. if(!($start<=0)) { ?> <a href='index.php?start=<?php echo $prev; ?>'>Previous</a> <?php } //show page numbers. //set variable for first page. $i = 1; for($x=0; $x<$record_count; $x = $x + $per_page) { if($start != $x) { ?> <a href="index.php?start=<?php echo $x; ?>"><?php echo $i; ?></a> <?php } else { ?> <a href="index.php?start=<?php echo $x; ?>"><b><?php echo $i; ?></b></a> <?php } $i++; } //show next button if(!($start>=$record_count-$per_page)) { ?> <a href='index.php?start=<?php echo $next; ?>'>Next</a> <?php } } ?> Link to comment https://forums.phpfreaks.com/topic/195646-pagination-help/#findComment-1027965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.