Hi,
i am trying to do make a simple search using a textbox + a dropdown. with the following code search works properly using textbox only or with dropdown selection but when the necessary line for making concatenating is used ($query2 .="Limit ...";) that pagination does not work with it and shows all data which was searched in a page. please help me with this.
i am trying to do make a simple search using a textbox + a dropdown. with the following code search works properly using textbox only or with dropdown selection but when the necessary line for making concatenating is used ($query2 .="Limit ...";) that pagination does not work with it and shows all data which was searched in a page. please help me with this.
Code:
$search = $_GET['search']; //textbox search $sele = $_GET['sele']; //dropdown if (isset($_GET['search']) && $_GET['search'] !="") { $conn = mysql_connect("localhost","root",""); mysql_select_db("kyp"); if ($_GET['sele'] == "1") { $query2 = mysql_query("SELECT * FROM users WHERE username LIKE '%".$_GET["search"]."%' "); } elseif ($_GET['sele'] !== "1") { $query2 = mysql_query("SELECT * FROM users WHERE username LIKE '%".$_GET["search"]."%' AND states='".$_GET['sele']."' "); } } $Per_Page = 1; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $query2 .=mysql_query(" ORDER BY username ASC LIMIT $Page_Start , $Per_Page"); //this line does not work and can not make pagination while($row = mysql_fetch_array($query2)) { echo $row['username']."<br/>"; echo $row['city']."<br>"; echo $row['tel']."<br>"; echo $row['address']."<br>"; echo "<hr color=\"blue\">"; } echo "<br>"; if($Prev_Page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&search=$_GET[search]'><< Back</a> "; } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$i&search=$_GET[search]'>$i</a> "; } else { echo "<b style='color:red;'> $i </b>"; } } if($Page!=$Num_Pages) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&search=$_GET[search]'>Next>></a> "; } mysql_close($conn);
Comment