Jump to content

Search problems


spearchilduser

Recommended Posts

im trying to just search and display results from a price drop box but it doesnt seem to work it ignores the while statement and just prints the entire database

 

heres my code if it helps

 

<?php

mysql_connect("localhost", "root") or die(mysql_error()); // makes a connection

mysql_select_db("estate_agents") or die('I cannot connect to the database because: ' . mysql_error()); //conects to the database

 

$price = $_POST['Price'];

$query = "SELECT * FROM properties";

$result = mysql_query($query);

 

 

switch ($price)

{

case '1' : $price_low = 100; $price_high = 300 ;  " (I would like to pay less and get less specifications) < ".$price_low."-".$price_high.">"; break; 

case '2' : $price_low = 200; $price_high = 500;  " (I would like to pay for what I get so what I get is equivalent to the price) < ".$price_low."-".$price_high.">"; break;

case '3' : $price_low = 400; $price_high = 700;  " (I would prefer to Pay as much as possible to get the best computer) < ".$price_low."-".$price_high.">"; break;

case '4' : $price_low = 600; $price_high = 900 ; " (I have no preference) < ".$price_low."-".$price_high.">"; break;

case '5' : $price_low = 900; $price_high = 2000 ; " (I have no preference) < ".$price_low."-".$price_high.">"; break;

}

//gives the different vaules for each drop down option from the input form for price

 

 

?>

 

<table border="1" width="100%" height="10">

 

  <tr>

    <td bgcolor="#FFFFFF">House Number</td>

    <td bgcolor="#FFFFFF">Street NamePrice</td>

    <td bgcolor="#FFFFFF">Area</td>

    <td bgcolor="#FFFFFF">Postcode</td>

<td bgcolor="#FFFFFF">Type of Property</td>

<td bgcolor="#FFFFFF">Number of Bedrooms</td>

<td bgcolor="#FFFFFF">Number of Bathrooms</td>

    <td bgcolor="#FFFFFF">Price</td>

<td bgcolor="#FFFFFF">Image</td>

    <td bgcolor="#FFFFFF">Description</td>

  </tr>

 

 

 

 

<?php

 

while ($row = mysql_fetch_array($result))

{

 

if (($row['Price'] >= $price_low) && ($row['Price'] <= $price_high)) //price

 

?>

 

 

 

<tr>

  <td align="center" bgcolor="#FFFFFF"><?php echo $row["Address_Line_1"]; ?></a></td> <!-- fetch the model name from the database and display in table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Address_Line_2"]; ?> </td> <!-- fetch the price from the database and display in the table-->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Area"]; ?> </td> <!-- fetch the type from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Post_Code"]; ?> </td> <!-- fetch the type from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Type_of_Property"]; ?> </td> <!-- fetch the size from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Number_of_Bedrooms"]; ?> </td> <!-- fetch the skill from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Number_of_Bathrooms"]; ?> </td> <!-- fetch the style from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Price"]; ?> </td> <!-- fetch the style from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Property_Image"]; ?> </td> <!-- fetch the style from the database and display in the table -->

  <td align="center" bgcolor="#FFFFFF"><?php print $row["Description"]; ?> </td> <!-- fetch the style from the database and display in the table -->

 

</tr>

 

<?php

 

}//while

 

?>

 

i am newish to php any help is much appreciated

Link to comment
Share on other sites

I don't know what while you think you have a problem with, but it looks to me the issue is with a malformed if statement - try this:

?php

while ($row = mysql_fetch_array($result))
{
      
      if (($row['Price'] >= $price_low) && ($row['Price'] <= $price_high)) { //price

?>



<tr>
           <td align="center" bgcolor="#FFFFFF"><?php echo $row["Address_Line_1"]; ?></a></td> <!-- fetch the model name from the database and display in table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Address_Line_2"]; ?> </td> <!-- fetch the price from the database and display in the table-->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Area"]; ?> </td> <!-- fetch the type from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Post_Code"]; ?> </td> <!-- fetch the type from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Type_of_Property"]; ?> </td> <!-- fetch the size from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Number_of_Bedrooms"]; ?> </td> <!-- fetch the skill from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Number_of_Bathrooms"]; ?> </td> <!-- fetch the style from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Price"]; ?> </td> <!-- fetch the style from the database and display in the table -->
            <td align="center" bgcolor="#FFFFFF"><?php print $row["Property_Image"]; ?> </td> <!-- fetch the style from the database and display in the table -->
           <td align="center" bgcolor="#FFFFFF"><?php print $row["Description"]; ?> </td> <!-- fetch the style from the database and display in the table -->
         
         </tr>

<?php
    }//if            
   }//while            
      
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.