Jump to content

hemanthkumar

New Members
  • Posts

    2
  • Joined

  • Last visited

hemanthkumar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Actually .... from last two dayz i worked on this for my project . Corrected that navigation problem and included in my project. that'y i posted here.. check it if you find any problem let me know i ll try to correct that.even i don't know the posted date.i just upload it here.
  2. Try this you will get result and make sure change it according to your database : if it not works please let me know. <html> <head> <title>pagination</title> </head> <body> <form method="post" action="" > <input type="text" value="<?php $input = isset($_POST['search'])?$_POST['search']:'';?>" name="search" placeholder="search here"/> <input type="submit" value="search"/></form><br /> <?php $username = "root"; $password = ""; $hostname = "localhost"; $dbconnect = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("lovetran_lth",$dbconnect) or die("Could not select examples"); $sorts = array('User_ID'=>'User_ID','First_Name'=>'First_Name','Last_Name'=>'Last_Name'); $sort_bys = array('asc','desc'); $limit = 10; $table = 'users'; $start = (isset($_REQUEST['start'])) ? (int)$_REQUEST['start'] : 0; $sort = (isset($_REQUEST['sort'])) ? $_REQUEST['sort'] : 'First_Name'; $sort_by = (isset($_REQUEST['sort_by'])) ? $_REQUEST['sort_by'] : 'asc'; $eu = $start; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; if($sort_by == 'asc') { $sort_order = 'desc'; } else { $sort_order = 'asc'; } echo "<table align='center' border='2'>" ; echo "<tr>"; echo "<tr> <th>ID</th>"; foreach($sorts as $key=>$value) { if (isset($_REQUEST['search'])) { $var=$_REQUEST['search']; echo "<th><a href='?search=$var&sort=$key&sort_by=$sort_order&start=$eu '>$value $eu</a></th>"; } else { echo "<th><a href='?sort=$key&sort_by=$sort_order&start=$eu'>$value $eu</a></th>"; } } echo "</tr>"; //this is working// if (isset($_REQUEST['search'])) { $result= mysql_query ("SELECT * FROM $table where First_Name like '%" . $_REQUEST['search'] . "%' or Last_Name like '%" . $_REQUEST['search'] . "%' or User_ID like '%" . $_REQUEST['search'] . "%' ORDER BY $sort $sort_by "); $search_result=mysql_num_rows($result); $nume=$search_result; echo "Totals of record search: $nume | Page limit: $limit <br/>"; if ($_REQUEST['search'] =='') { $query="SELECT COUNT(*) FROM $table "; $result=mysql_query($query); list($nume) = mysql_fetch_row($result); $query="SELECT * FROM $table ORDER BY $sort $sort_by limit $eu, $limit"; $result=mysql_query($query); $count = (isset($eu) && $eu > 0) ? $eu+1 : 1; while($rows = mysql_fetch_array($result)) { echo "<tr >"; echo "<td>"; echo $count++; echo "</td>";echo "<td >$rows[user_ID]</td>"; echo "<td>$rows[First_Name]</td>";echo "<td>$rows[Last_Name]</td>"; echo "</tr>"; } } //i have to give input for this then // else { echo "$search_result"; echo " record of <b>" . $_REQUEST['search'] . "</b> found"; echo "if input page".$eu; $query="SELECT * FROM $table where First_Name like '%" . $_REQUEST['search'] . "%' or Last_Name like '%" . $_REQUEST['search'] . "%' or User_ID like '%" . $_REQUEST['search'] . "%' ORDER BY $sort $sort_by limit $eu,$limit"; echo $query; $result= mysql_query($query); $count = (isset($eu) && $eu > 0) ? $eu+1 : 1; while($rows = mysql_fetch_array($result)) { echo "<tr >"; echo "<td>"; echo $count++; echo "</td>"; echo "<td >$rows[user_ID]</td>"; echo "<td>$rows[First_Name]</td>"; echo "<td>$rows[Last_Name]</td>"; echo "</tr>"; } } if ($search_result=='0') { echo "<b> (NO Results) </b>"; } } else { $query="SELECT COUNT(*) FROM $table"; $result=mysql_query($query); list($nume) = mysql_fetch_row($result); $query="SELECT * FROM $table ORDER BY $sort $sort_by limit $eu, $limit"; echo "sorting" .$query; $result=mysql_query($query); $count = (isset($eu) && $eu > 0) ? $eu+1 : 1; while($rows = mysql_fetch_array($result)){ echo "<tr >"; echo "<td>"; echo $count++; echo "</td>"; echo "<td>$rows[user_ID]</td>"; echo "<td>$rows[First_Name]</td>"; echo "<td>$rows[Last_Name]</td>"; echo "</tr>"; } } echo "</table>"; if($nume > $limit ) { echo "<table align='center' border='1'><tr><td>"; if($back >=0) { if(isset($_POST['search'])) { $_REQUEST['start'] = $back; $_REQUEST['search'] = $_REQUEST['search']; } { $_REQUEST['start'] = $back; } $q = http_build_query($_REQUEST,'','&'); print "<a href='?$q'>PREV</a>"; } echo "</td><td>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit) { if($i <> $eu) { if(isset($_POST['search'])) { $_REQUEST['start'] = $i;$_REQUEST['search'] = $_REQUEST['search']; } else { $_REQUEST['start'] = $i; } $q = http_build_query($_REQUEST,'','&'); echo " <a href='?$q'>$l</a> "; } else { echo "<font color=red>$l</font>"; } $l=$l+1; } echo "</td><td>"; if($this1 < $nume) { if(isset($_POST['search'])) { $_REQUEST['start'] = $next; $_REQUEST['search'] = $_REQUEST['search']; } else { $_REQUEST['start'] = $next; } $q = http_build_query($_REQUEST,'','&'); print "<a href='?$q'>NEXT</a>"; } echo "</td></tr></table>"; } mysql_close($dbconnect); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.