sonnieboy Posted April 22, 2015 Share Posted April 22, 2015 Total <?php echo $num_rows;?> Records : <?php echo $num_pages;?> Page(s) : <?php if($prev_page) { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$prev_page&$searchType'><< Back</a> "; } for($i=1; $i<=$num_pages; $i++){ if($i != $page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&$searchType&sort=$sort&order=$order'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($page!=$num_pages) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$next_page&$searchType'>Next>></a> "; } Total 4899 Records : 245 Page(s) : << Back [ 1 ] 2 [ 3 ][ 4 ][ 5 ][ 6 ][ 7 ][ 8 ][ 9 ][ 10 ][ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ][ 31 ][ 32 ][ 33 ][ 34 ][ 35 ][ 36 ][ 37 ][ 38 ][ 39 ][ 40 ][ 41 ][ 42 ][ 43 ][ 44 ][ 45 ][ 46 ][ 47 ][ 48 ][ 49 ][ 50 ][ 51 ][ 52 ][ 53 ][ 54 ][ 55 ][ 56 ][ 57 ][ 58 ][ 59 ][ 60 ][ 61 ][ 62 ][ 63 ][ 64 ][ 65 ][ 66 ][ 67 ][ 68 ][ 69 ][ 70 ][ 71 ][ 72 ][ 73 ][ 74 ][ 75 ][ 76 ][ 77 ][ 78 ][ 79 ][ 80 ][ 81 ][ 82 ][ 83 ][ 84 ][ 85 ][ 86 ][ 87 ][ 88 ][ 89 ][ 90 ][ 91 ][ 92 ][ 93 ][ 94 ][ 95 ][ 96 ][ 97 ][ 98 ][ 99 ][ 100 ][ 101 ][ 102 ][ 103 ][ 104 ][ 105 ][ 106 ][ 107 ][ 108 ][ 109 ][ 110 ][ 111 ][ 112 ][ 113 ][ 114 ][ 115 ][ 116 ][ 117 ][ 118 ][ 119 ][ 120 ][ 121 ][ 122 ][ 123 ][ 124 ][ 125 ][ 126 ][ 127 ][ 128 ][ 129 ][ 130 ][ 131 ][ 132 ][ 133 ][ 134 ][ 135 ][ 136 ][ 137 ][ 138 ][ 139 ][ 140 ][ 141 ][ 142 ][ 143 ][ 144 ][ 145 ][ 146 ][ 147 ][ 148 ][ 149 ][ 150 ][ 151 ][ 152 ][ 153 ][ 154 ][ 155 ][ 156 ][ 157 ][ 158 ][ 159 ][ 160 ][ 161 ][ 162 ][ 163 ][ 164 ][ 165 ][ 166 ][ 167 ][ 168 ][ 169 ][ 170 ][ 171 ][ 172 ][ 173 ][ 174 ][ 175 ][ 176 ][ 177 ][ 178 ][ 179 ][ 180 ][ 181 ][ 182 ][ 183 ][ 184 ][ 185 ][ 186 ][ 187 ][ 188 ][ 189 ][ 190 ][ 191 ][ 192 ][ 193 ][ 194 ][ 195 ][ 196 ][ 197 ][ 198 ][ 199 ][ 200 ][ 201 ][ 202 ][ 203 ][ 204 ][ 205 ][ 206 ][ 207 ][ 208 ][ 209 ][ 210 ][ 211 ][ 212 ][ 213 ][ 214 ][ 215 ][ 216 ][ 217 ][ 218 ][ 219 ][ 220 ][ 221 ][ 222 ][ 223 ][ 224 ][ 225 ][ 226 ][ 227 ][ 228 ][ 229 ][ 230 ][ 231 ][ 232 ][ 233 ][ 234 ][ 235 ][ 236 ][ 237 ][ 238 ][ 239 ][ 240 ][ 241 ][ 242 ][ 243 ][ 244 ][ 245 ] Next>> //A search produces the following: Total 653 Records : 33 Page(s) : 1 [ 2 ][ 3 ][ 4 ][ 5 ][ 6 ][ 7 ][ 8 ][ 9 ][ 10 ][ 11 ][ 12 ][ 13 ][ 14 ][ 15 ][ 16 ][ 17 ][ 18 ][ 19 ][ 20 ][ 21 ][ 22 ][ 23 ][ 24 ][ 25 ][ 26 ][ 27 ][ 28 ][ 29 ][ 30 ][ 31 ][ 32 ][ 33 ] Next>> Dear experts, This issue is probably not for the faint hearted. I have been struggling for days now trying to resolve pagination issue with no success. User performs a search and if record exists, they get displayed. Some of searches produce more than 60 rows of records. Using paging, each page contains a maximum of 20 rows or records. The remaining are spread out to other pages. The issue is that assume that I did a search which produces 65 records which amounts to 4 pages, when I click either Next >> or a page number, the number explodes. Here is example of what I mean: If you click Next >> or page number, then the same results explode to this: I believe the issue has to do with the search parameter called $searchType that I am passing to the navigation link: Any idea how to resolve this? I will be glad to post the code used as search parameters. Thank you very much in advance Quote Link to comment Share on other sites More sharing options...
sonnieboy Posted April 22, 2015 Author Share Posted April 22, 2015 $fields = array( 'projectTitle' => array('field' => 'b.BidTitle', 'searchType' => 'like'), 'BidType' => array('field' => 'b.BidType', 'searchType' => 'equal'), 'BidStatus' => array('field' => 'b.BidStatus', 'searchType' => 'equal'), 'department' => array('field' => 'b.AliasID', 'searchType' => 'equal'), 'bidId' => array('field' => 'b.BidID', 'searchType' => 'like'), 'txtFromDate' => array('field' => 'b.BidDate', 'searchType' => 'gte'), 'txtToDate' => array('field' => 'b.BidDate', 'searchType' => 'lte'), 'txtFromDueDate' => array('field' => 'b.DueDate', 'searchType' => 'gte'), 'txtToDueDate' => array('field' => 'b.DueDate', 'searchType' => 'lte'), 'bidDate' => array('field' => 'b.BidDate', 'searchType' => 'equal'), 'dueDate' => array('field' => 'b.DueDate', 'searchType' => 'equal') ); $where = array(); $searchType = ""; foreach($fields as $fieldPost => $field) { if(isset($_POST[$fieldPost]) && strlen($_POST[$fieldPost]) > 0) { if($field['searchType'] == 'like') { $where[] = "".$field['field']." LIKE '%" . ms_escape_string($_POST[$fieldPost]) . "%'"; } elseif ($field['searchType'] == 'gte') { $where[] = "".$field['field']." >= '" . ms_escape_string($_POST[$fieldPost]) . "'"; } elseif ($field['searchType'] == 'lte') { $where[] = "".$field['field']." <= '" . ms_escape_string($_POST[$fieldPost]) . "'"; } else { $where[] = "".$field['field']." = '" . ms_escape_string($_POST[$fieldPost]) . "'"; } $searchType .= (empty($searchType) ? "" : "&") . $fieldPost . "=" . $_POST[$fieldPost]; } if(isset($_GET[$fieldPost]) && strlen($_GET[$fieldPost]) > 0) { if($field['searchType'] == 'like') { $where[] = "".$field['field']." LIKE '%" . ms_escape_string($_POST[$fieldPost]) . "%'"; } elseif ($field['searchType'] == 'gte') { $where[] = "".$field['field']." >= '" . ms_escape_string($_POST[$fieldPost]) . "'"; } elseif ($field['searchType'] == 'lte') { $where[] = "".$field['field']." <= '" . ms_escape_string($_POST[$fieldPost]) . "'"; } else { $where[] = "".$field['field']." = '" . ms_escape_string($_POST[$fieldPost]) . "'"; } $searchType .= (empty($searchType) ? "" : "&") . $fieldPost . "=" . $_GET[$fieldPost]; // echo $searchType; } } $sql = " SELECT c.* FROM ( SELECT TOP 1000000 ROW_NUMBER() OVER(ORDER BY b.ID DESC) AS RowID,b.ID,CONVERT(VARCHAR(11), b.BidDate, 106) sBidDate,CONVERT(VARCHAR(11), b.DueDate, 106) sDueDate,b.BidTitle,b.DueTime,b.BidID,b.BidIDFile, da.DeptAlias,b.BidType,CASE WHEN b.AwardDate ='01/01/1900' Then NULL ELSe convert(char(10),b.AwardDate,101)END AS AwardDate, CONVERT(VARCHAR(11), b.LastUpdate, 106) LastUpdate,s.Status FROM bids b inner join DeptALIAS da on b.AliasID = da.AliasID inner join Dept d on da.DeptCode = d.DeptCode inner join status s on b.BidStatus=s.StatusId " . ( count($where) > 0 ? " WHERE " . implode(' AND ', $where) : " " ) . " ORDER BY $sort $order ) AS c WHERE c.RowID BETWEEN $row_start AND $row_end ORDER BY c.RowID "; <form id="form1" action="Search.php" method="post" target="SearchResults"> Since I could not modify y original post, I decided to bring to your attention what I discovered now that I thought could be the problem. First, on my markup, when I try using the post method as shown above, then the WHERE clauses are ignored. As a result, all those records are displayed. However, when I change to get method which is what I found out I should be using when performing a search, I get a message that no records found. I know this is not true. Does anyone know what I need to change in the following code above: BTW: How do I get my code to show up below my comments? Everything is posted at top of page. Quote Link to comment Share on other sites More sharing options...
Solution sonnieboy Posted April 22, 2015 Author Solution Share Posted April 22, 2015 where[] = "".$field['field']." <= '" . ms_escape_string($_POST[$fieldPost]) . "'"; //to this line where[] = "".$field['field']." <= '" . ms_escape_string($_GET[$fieldPost]) . "'"; I have resolved this problem. I changed this line: 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.