mysql results error on php -
mysql results error on php -
hello below code query submit from.. no of rows correctly count , show in page , result rows not show in page , show "no results found, please search again", cant find error on code, can help find it..
<? ### debug $debugp = 0 ; ### end debug include 'db_connector.php'; require_once('myfunctions.php'); include('header.php'); #defauts $maxrows_p = 10; $pagenum_p = 0; if (isset($_get['pagenum_p'])) { $pagenum_p = $_get['pagenum_p']; } $startrow_p = $pagenum_p * $maxrows_p; $limit = ' limit '.$startrow_p.', '.$maxrows_p; ## start building sql varables advanced search ###add city if(isset($_request['city']) && ($_request['city'] != '')) $search[] = ' city = "'.$_request['city'].'"'; ###add state if(isset($_request['district']) && ($_request['district'] != '')) $search[] = ' district = "'.$_request['district'].'"'; ###add lot size if(isset($_request['lot_size']) && ($_request['lot_size'] != '')) $search[] = ' perches >= '.$_request['lot_size']; $search[] = ' availibility = "0" '; ###implode search string on ' , '; $searchstr = @implode(' , ',$search); $sql = 'select * properties status="1" and'; ###status=1 , $sql .= $searchstr; ###add column sorting if($_request['sort'] != '') $sort = ' order added asc '; else $sort = $_request['sort']; ### debug if($debugp) echo 'advanced search sql<hr>'.$sql; $error['results'] = 'no results found, please search again'; ###} ### finished building search sql , execting ##### $sql_with_limit = $sql . $sort . $limit; if($debugp) echo "<hr>property search limit sql: $sql_with_limit"; ###perform search $searchresults = mysql_query($sql.$sql_with_limit); ### build output #### if (isset($_get['totalrows_p'])) { $totalrows_p = $_get['totalrows_p']; } else { if($debugp) echo "<hr>property out limit sql: $sql $sort"; $all_p = mysql_query($sql.$sort); $totalrows_p = mysql_num_rows($all_p); if($debugp) echo "<br>result rows $totalrows_p"; } $totalpages_p = ceil($totalrows_p/$maxrows_p)-1; if($debugp) echo "<hr>builting query string limit: "; ###build query string foreach($_get $name => $value){ if($name != "pagenum_p") $querystring_p .= "&$name=$value"; } if($debugp) echo $querystring_p; ?> <div align="left" class="loctext">home<span class="locarrow"> > </span> search results</div> <hr size="1" color="#666666"> <table border="0" align="center"> <tr> <td align="center"> <?php if ($pagenum_p > 0) { ### show if not first page ?> < href="<?php printf("%s?pagenum_p=%d%s", $currentpage, 0, $querystring_p); ?>" class="pagelink">first</a> | <?php } ### show if not first page ?> <?php if ($pagenum_p > 0) { ### show if not first page ?> < href="<?php printf("%s?pagenum_p=%d%s", $currentpage, max(0, $pagenum_p - 1), $querystring_p); ?>" class="pagelink">previous</a> | <?php } ### show if not first page ?> <?php if ($pagenum_p < $totalpages_p) { ### show if not lastly page ?> < href="<?php printf("%s?pagenum_p=%d%s", $currentpage, min($totalpages_p, $pagenum_p + 1), $querystring_p); ?>" class="pagelink">next</a> | <?php } ### show if not lastly page ?> <?php if ($pagenum_p < $totalpages_p) { ### show if not lastly page ?> < href="<?php printf("%s?pagenum_p=%d%s", $currentpage, $totalpages_p, $querystring_p); ?>" class="pagelink">last</a> <?php } ### show if not lastly page ?> </td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="pagetext" >showing: <strong><?php echo ($startrow_p + 1) ?> <?php echo min($startrow_p + $maxrows_p, $totalrows_p) ?> of <?php echo $totalrows_p ?></strong> listings</td> <td align="right" class="pagetext"></td> </tr> </table></td> </tr> <tr> <td height="5">xx</td> </tr> <tr> <td><table width="100%" border="0" cellspacing="1" cellpadding="4" class="resborder"> <tr> <td class="coltext">address</td> <td class="coltext">city</td> <td class="coltext">st</td> <td class="coltext">price</td> <td class="coltext">beds</td> <td class="coltext">baths</td> <td class="coltext">sqft</td> </tr> <?php while($row_p = @mysql_fetch_assoc($searchresults)) { ?> <tr valign="top"> <td class="bodytext"><?php echo $row_p['address']; ?></td> <td class="bodytext"><?php echo $row_p['city']; ?></td> <td class="bodytext"><?php echo $row_p['district']; ?></td> <td class="bodytext"><?php echo money($row_p['price'],1); ?></td> <td class="bodytext"><?php echo $row_p['rooms']; ?></td> <td class="bodytext"> </td> <td class="bodytext"><?php echo $row_p['floor']; ?></td> </tr> </table></td> </tr> <? } ?> </table></td> </tr> <tr> <td height="5">xx</td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="pagetext"> </td> <td align="right"></td> </tr> </table></td> </tr> </table> <p> </p> <? ## if no results found if(@mysql_num_rows($searchresults)<=0){ foreach($error $name => $value) print '<div align=center class="error">'.$name . ': ' . $value.'</div>'; } ##fetch footer ?> <script> document.getelementbyid('loading').style.display = 'none'; </script>
try changing:
###perform search $searchresults = mysql_query($sql.$sql_with_limit);
to:
###perform search $searchresults = mysql_query($sql_with_limit);
php mysql
Comments
Post a Comment