开发者

mysql results error on php

开发者 https://www.devze.com 2023-03-19 10:08 出处:网络
hello below is my code for a query with submit from..the no of rows are correctly count and show in the page and the result rows are not show in my page and show \"No results found, please search agai

hello below is my code for a query with submit from.. the no of rows are correctly count and show in the page and the result rows are not show in my page and show "No results found, please search again", i cant find the error on my code, can anyone help to 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 开发者_JAVA百科sql for GET varables for 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 to search string on ' and ';
        $searchStr = @implode(' and ',$search);


        $sql = 'select * FROM properties WHERE status="1" and'; ###status=1 and
        $sql .= $searchStr;

        ###Add column sorting
        if($_REQUEST['sort'] != '')
            $sort = ' order by 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 and execting #####
    $sql_with_limit = $sql . $sort . $limit;


    if($debugP)
        echo "<hr>Property Search with 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 with 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 for Limit: ";

    ###Build query string
    foreach($_GET as $name => $value){
        if($name != "pageNum_p")
            $queryString_p .= "&$name=$value";
    }

    if($debugP)
        echo $queryString_p;


?>
<div align="left" class="locText">Home<span class="locArrow">&nbsp;>&nbsp;</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 last 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 last page ?>
      <?php if ($pageNum_p < $totalPages_p) { ### Show if not last page ?>
      < href="<?php printf("%s?pageNum_p=%d%s", $currentPage, $totalPages_p, $queryString_p); ?>" class="pageLink">Last</a>
      <?php } ### Show if not last 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) ?> to <?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">&nbsp;</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">&nbsp;</td>
          <td align="right"></td>
        </tr>
      </table></td>
  </tr>
</table>
<p>&nbsp;</p>
<? 
    ## if no results where found
    if(@mysql_num_rows($searchResults)<=0){
        foreach($error as $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);
0

精彩评论

暂无评论...
验证码 换一张
取 消