plodos Posted August 27, 2008 Share Posted August 27, 2008 <?php include("dbconfig.php"); function title_case($title) { // deleted } $search = mysql_real_escape_string($_POST['search']); $type = mysql_real_escape_string($_POST['type']); $page = $_GET["page"]; if(empty($page) or !is_numeric($page)){ $page = 1; } $limit = 25; $query1 = mysql_query("select * from person where $type like '%$search%'") or die (mysql_error () ); $rowNumber = mysql_num_rows($query1); $pageNumber = ceil($rowNumber / $limit); $start = ($page-1)*$limit; $data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ()); while($info=mysql_fetch_array($data)) { if($info['no']=="1") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } if($info['no']=="2") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } } if($page > 1){ $back = $page-1; echo "<p align=\"center\"><b><a href=\"search.php?page=$back\"><< Back </a>"; }else{ echo "<p align=\"center\"><b> << Back "; } echo " | "; if($page>=$pageNumber){ echo "Next >> </b></p>"; }else{ $next = $page+1; echo "<a href=\"search.php?page=$next\">Next >></a></b></p>"; } ?> Im trying to using paging 0-25, 25-50 ....... first page is listing all records 0-25, but when I click to next page....program is giving there errors?... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like '%%'' at line 1 I used this paging code before, i didnt face any problem....but now this scipts first page is showing the records 0-25, why the second page is giving this error ? Some of the mysql datas are uppercase/lowercase like ERIK, Erik, erik...and im trying the search with lowercase...it can be an error? without paging $data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ()); while($info=mysql_fetch_array($data)) { if($info['no']=="1") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } if($info['no']=="2") { echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>"; } } I want to show these records with paging? :S ? :S ? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 27, 2008 Share Posted August 27, 2008 I'm pretty sure you're just losing your search value. When you click next you lose your $_POST value submitted on the first list of links so mysql doesn't know what to search for, I'd suggest passing it to the next page in a session or $_GET (preferred if it's not sensitive information). Also, make sure it won't let you do empty searches . If you had all errors enabled it would report you're trying to use a $_POST variable that is not set. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 27, 2008 Share Posted August 27, 2008 And, you will be doing yourself a BIG favor if you were to create your queries as string variables so you can echo them to the page when they fail. The SQL error that is returned only contains part of the query making it difficult to debug. Example: $query = "select * from person where $type like '%$search%'"; $result = mysql_query($query) or die (mysql_error ()."<br>Query: $query"); Quote Link to comment Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 yes, ım losing my search value Query: select * from person where like '%%' it is empty if I use like that, just an idea...I dont knpw how to write:) echo "<p align=\"center\"><b><a href=\"search.php?page=$back&search=$search&type=$type\"><< Back </a>"; What must I do for work this code ? Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 27, 2008 Share Posted August 27, 2008 Try replancing your assignment of the $search value with this: $search = (isset($_POST['search'])) ? $_POST['search'] : $_GET['search']; $search = mysql_real_escape_string($search); Quote Link to comment Share on other sites More sharing options...
plodos Posted August 27, 2008 Author Share Posted August 27, 2008 this is working now, special thanks for mjdamato and other writer.... 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.