943,626 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 490
  • PHP RSS
Aug 18th, 2009
0

PHP Paging Problem :(

Expand Post »
This is a page name search.php
html Syntax (Toggle Plain Text)
  1. <form action="/ap/demo_paging1.php" method="post">
  2.  
  3. <input type="text" value="Enter Site ID" name="a" class="textfield_effect" maxlength="30" onfocus="this.value=''">
  4. <input type="submit" value="Search ID " />
  5. </form>

and I post value a to another page name demo_paging1.php

when I put Query WHERE SiteId REGEXP '$a' It does not show me the desire result

php Syntax (Toggle Plain Text)
  1. <?
  2. require "config.php"; // All database details will be included here
  3.  
  4. $page_name="demo_paging1.php"; // If you use this code with a different page ( or file ) name then change this
  5.  
  6. $a= $_POST["a"];
  7. $start=$_GET['start'];
  8. if(strlen($start) > 0 and !is_numeric($start)){
  9. echo "Data Error";
  10. exit;
  11. }
  12.  
  13.  
  14. $eu = ($start - 0);
  15. $limit = 10; // No of records to be shown per page.
  16. $this1 = $eu + $limit;
  17. $back = $eu - $limit;
  18. $next = $eu + $limit;
  19.  
  20.  
  21. /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
  22. $query2=" SELECT * FROM leaseentry WHERE SiteId REGEXP '$a'";
  23. $result2=mysql_query($query2);
  24. echo mysql_error();
  25. $nume=mysql_num_rows($result2);
  26. /////// The variable nume above will store the total number of records in the table////
  27.  
  28. /////////// Now let us print the table headers ////////////////
  29. $bgcolor="#f1f1f1";
  30. echo "<TABLE width=100% align=center cellpadding=0 cellspacing=0> <tr>";
  31. echo "<td bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Site ID</font></td>";
  32. echo "<td bgcolor='dfdfdf' >&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Code</font></td>";
  33. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Owner Name</font></td>";
  34. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>Lease Agreement</font></td>";
  35. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>LA Start Date</font></td>";
  36. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>LA END Date</font></td>";
  37. echo "<td bgcolor='dfdfdf'>&nbsp;<font face='arial,verdana,helvetica' color='#000000' size='4'>PO</font></td>
  38. </tr>";
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
  45. $query=" SELECT * FROM leaseentry limit $eu, $limit ";
  46. $result=mysql_query($query);
  47. echo mysql_error();
  48.  
  49. //////////////// Now we will display the returned records in side the rows of the table/////////
  50. while($noticia = mysql_fetch_array($result))
  51. {
  52. if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
  53. else{$bgcolor='#f1f1f1';}
  54.  
  55. echo "<tr >";
  56. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'>$noticia[0]</font></td>";
  57. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'>$noticia[1]</font></td>";
  58. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'>$noticia[2]</font></td>";
  59. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'><a href=".$noticia['LA'].">".$noticia['ch']."</a></font></td>";
  60. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'>".date("j-F-Y",strtotime($noticia['LAPeriodStart']))."</a></font></td>";
  61. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'>".date("j-F-Y",strtotime($noticia['LAPeriodEnd']))."</a></font></td>";
  62. echo "<td align=left bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='1'><a href=".$noticia['PO'].">".$noticia['ch']."</a></font></td>";
  63. echo "</tr>";
  64. }
  65. echo "</table>";
  66. ////////////////////////////// End of displaying the table with records ////////////////////////
  67.  
  68. ///////////////////////////////
  69. if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging
  70.  
  71. /////////////// Start the bottom links with Prev and next link with page numbers /////////////////
  72. echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>";
  73. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  74. if($back >=0) {
  75. print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
  76. }
  77. //////////////// Let us display the page links at center. We will not display the current page as a link ///////////
  78. echo "</td><td align=center width='30%'>";
  79. $i=0;
  80. $l=1;
  81. for($i=0;$i < $nume;$i=$i+$limit){
  82. if($i <> $eu){
  83. echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
  84. }
  85. else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
  86. $l=$l+1;
  87. }
  88.  
  89.  
  90. echo "</td><td align='right' width='30%'>";
  91. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  92. if($this1 < $nume) {
  93. print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
  94. echo "</td></tr></table>";
  95.  
  96. }// end of if checking sufficient records are there to display bottom navigational link.
  97. ?>
Similar Threads
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Aug 18th, 2009
0

Re: PHP Paging Problem :(

WHERE SiteId REGEXP '$a' I use the above quert in both Sql Queries.
When I press search it shows first 10 records which are desire, but on page 2 or any other page except page 1 it shows following error related to $a
Quote ...
Got error 'empty (sub)expression' from regexp
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\ap\demo_paging1.php on line 37
Site ID Code Owner Name Lease Agreement LA Start Date LA END Date PO
Got error 'empty (sub)expression' from regexp
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\ap\demo_paging1.php on line 62
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Aug 18th, 2009
0

Re: PHP Paging Problem :(

please guide me.
how to post value of a to the paging 2 page?
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Aug 18th, 2009
0

Re: PHP Paging Problem :(

Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Aug 20th, 2009
0

Re: PHP Paging Problem :(

Please check my code and guide me.
Thanks
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Aug 20th, 2009
0

Re: PHP Paging Problem :(

Please tell me how I can put my SQL Query in session
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Proportional image
Next Thread in PHP Forum Timeline: Inputing checkboxes into a MySQL database





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC