nhojeinnor Posted May 4, 2010 Share Posted May 4, 2010 pls help me with my codes. i am calling this function to a new php file. what i want to do is when the ELSE CONDITION execute. the pages will display and when i click the pages. prev12345next will direct to next page. but the problem is.. it redirects to my IF CONDITION. where the the IF CONDITION will display the total output of the data. when no input value on the searchbox.. and paginates the records.. pls help.. tnx.. public function viewSearch($form) { $affid = $form['affid']; $site_id = $form['site_id']; if($affid==""){ $where1 =""; } else { $where1 = "affid = '$affid'" ; } if($site_id==""){ $where2 =""; } elseif($affid=="" || site_id==""){ $where2= "site_id = $site_id"; }else { $where2 ="AND site_id = $site_id"; } $where_condition = $where1 . $where2; $data = array(); if ($affid=="" && $site_id=="") { //max displayed per page $per_page = 30; //get start variable $start = $_GET['start']; //count max pages $max_pages = $record_count / $per_page; if (!$start) $start = 0; $count = mysql_num_rows(mysql_query("SELECT * FROM link ORDER BY site_id")); $sql = "SELECT * FROM link ORDER BY site_id LIMIT $start, $per_page"; $result = mysql_query($sql) or die(mysql_error()); while(($rows = mysql_fetch_array($result))) { $data[] = $rows; } $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev'>Prev</a> "; //set variable for first page $i=1; for ($x=0;$x<$count;$x=$x+$per_page) { if ($start!=$x) echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>$i</a> "; else echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>[$i]</a> "; $i++; } //show next button if (!($start>=$count-$per_page)) echo "<a href='{$_SERVER['PHP_SELF']}?start=$next'>Next</a> "; } else { //max displayed per page $per_pages = 5; //get start variable $starts = $_GET['starts']; //count max pages $max_pages = $counts / $per_pages; if (!$starts) $starts = 0; $counts = mysql_num_rows(mysql_query("SELECT * FROM link WHERE $where_condition ORDER BY site_id")); $sql = "SELECT * FROM link WHERE $where_condition ORDER BY site_id LIMIT $starts, $per_pages"; $results = mysql_query($sql) or die(mysql_error()); while(($rows = mysql_fetch_array($results))) { $data[] = $rows; } $prev = $starts - $per_pages; $next = $starts + $per_pages; //show prev button if (!($starts<=0)) echo "<a href=\"?starts=$prev\">Prev</a> "; //set variable for first page $i=1; for ($x=0;$x<$counts;$x=$x+$per_pages) { if ($starts!=$x) echo " <a href=\"?starts=$x\">$i</a> "; else echo " <a href=\"?starts=$x\">[$i]</a> "; $i++; } //show next button if (!($starts>=$counts-$per_pages)) echo "<a href=\"?starts=$next\">Next</a> "; } return $data; } Link to comment https://forums.phpfreaks.com/topic/200648-search-pagination/ Share on other sites More sharing options...
TeddyKiller Posted May 4, 2010 Share Posted May 4, 2010 Your code is messy, however.. I don't think I understand your question? What is it that you are wanting? Link to comment https://forums.phpfreaks.com/topic/200648-search-pagination/#findComment-1053007 Share on other sites More sharing options...
nhojeinnor Posted May 5, 2010 Author Share Posted May 5, 2010 else { //max displayed per page $per_pages = 30; //get start variable $starts = $_GET['starts']; //count max pages $max_pages = $counts / $per_pages; if (!$starts) $starts = 0; $counts = mysql_num_rows(mysql_query("SELECT * FROM link WHERE $where_condition ORDER BY site_id")); $sql = "SELECT * FROM link WHERE $where_condition ORDER BY site_id LIMIT $starts, $per_pages"; $results = mysql_query($sql) or die(mysql_error()); while(($rows = mysql_fetch_array($results))) { $data[] = $rows; } $prev = $starts - $per_pages; $next = $starts + $per_pages; //show prev button if (!($starts<=0)) echo "<a href='?starts=$prev'>Prev</a> "; //set variable for first page $i=1; for ($x=0;$x<$counts;$x=$x+$per_pages) { if ($starts!=$x) echo " <a href='?starts=$x'>$i</a> "; else echo " <a href='?starts=$x'>[$i]</a> "; $i++; } //show next button if (!($starts>=$counts-$per_pages)) echo "<a href='?starts=$next'>Next</a> "; } this is my else part.. what i want is when it execute.. and the pages will pages is shown.. like 1 2 3 4 5 , when i click 2, i want the page to be turn on page 2. but what is does is redirect to my IF condition. this is the part. public function viewSearch($form) { $affid = $form['affid']; $site_id = $form['site_id']; if($affid==""){ $where1 =""; } else { $where1 = "affid = '$affid'" ; } if($site_id==""){ $where2 =""; } elseif($affid=="" || site_id==""){ $where2= "site_id = $site_id"; }else { $where2 ="AND site_id = $site_id"; } $where_condition = $where1 . $where2; $data = array(); if ($affid=="" && $site_id=="") { //max displayed per page $per_page = 30; //get start variable $start = $_GET['start']; //count max pages $max_pages = $record_count / $per_page; if (!$start) $start = 0; $count = mysql_num_rows(mysql_query("SELECT * FROM link ORDER BY site_id")); $sql = "SELECT * FROM link ORDER BY site_id LIMIT $start, $per_page"; $result = mysql_query($sql) or die(mysql_error()); while(($rows = mysql_fetch_array($result))) { $data[] = $rows; } $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev'>Prev</a> "; //set variable for first page $i=1; for ($x=0;$x<$count;$x=$x+$per_page) { if ($start!=$x) echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>$i</a> "; else echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>[$i]</a> "; $i++; } //show next button if (!($start>=$count-$per_page)) echo "<a href='{$_SERVER['PHP_SELF']}?start=$next'>Next</a> "; } Link to comment https://forums.phpfreaks.com/topic/200648-search-pagination/#findComment-1053380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.