<body>
<h1><font color="red"> Search for Property</font></h1>
Please fill in the area to get the property you are looking for. <BR>
<form action="psearch.php" method="post">
<table>
<tr>
</tr>
<tr>
</tr>
<td>
Property Type:
</td>
<td>
<input type="checkbox" name="house" value="house"> House
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="checkbox" name="flat" value="flat"> Flat
</td>
</tr>
<tr>
<td>
Maximum Price in thousand <br>
eg. Enter '12' for £12,000:
</td>
<td>
<input type="text" name="maximum">
</td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
[TEXT]
Postcode, Price(Thousands), Image of the house, Number of Visits
HA2 2AP, 125, house2.jpg, 1
HA2 3AS, 157, house3.jpg, 5
HA3 5SW, 225, house4.jpg, 3
HA5 8KP, 325, house5.jpg, 11
NW1 9AP, 95, flat1.jpg, 30
NW2 4AP, 185, house7.jpg, 2
NW4 2AP, 123, house8.jpg, 19
NW7 6AP, 121, house9.jpg, 21
SL1 7DF, 23, flat2.jpg, 27
SL3 3SS, 99, flat3.jpg, 12
UB2 1RS, 123, house10.jpg, 0
[/TEXT]
$maximum=$_POST["maximum"];
$house=$_POST["house"];
$flat=$_POST["flat"];
$house1=substr($house,0,4);
$flat1=substr($flat,0,4);
$plist = "House.txt";
$filepointer = fopen($plist,"r");
$propertyArray = file ($plist);
print"<table>";
for ( $myCount = 0; $myCount < 1; $myCount++)
{
$aline = $propertyArray[$myCount];
print"<tr align=\"center\" style=\"text-transform: uppercase\"><strong>";
for ($myCount1 = 0; $myCount1 < count ($aline); $myCount1++)
{
$seperate = explode (",",$aline);
$postcode = $seperate[0];
$price = $seperate[1];
$image = $seperate[2];
$visits = $seperate[3];
print "<td>$postcode</td><td></td><td>$price</td><td></td><td>$image</td><td></td><td>$visits</td>";
}
print "</strong></tr>";
}
for ( $myCount = 1; $myCount < count ($propertyArray); $myCount++)
{
$aline = $propertyArray[$myCount];
print"<tr>";
for ($myCount1 = 0; $myCount1 < count ($aline); $myCount1++)
{
$seperate = explode(",",$aline);
$postcode = $seperate[0];
$price = $seperate[1];
$image = $seperate[2];
$visits = $seperate[3];
$prop = substr($image,0,4);
if (($flat1 == $prop) && ($maximum>$price))
#if ($maximum>$price)
{
echo "<td align=\"center\">$postcode</td><td></td><td align=\"center\">$price</td><td></td><td align=\"center\">$image</td><td></td><td align=\"center\">$visits</td>";
}
#else if (($house1 == $prop) && ($maximum>$price))
#{
#echo "<td align=\"center\">$postcode</td><td></td><td align=\"center\">$price</td><td></td><td align=\"center\">$image</td><td></td><td align=\"center\">$visits</td>";
#}
else
{
echo "do not print anything";
}
}
print "</tr>";
}
print"</table>";
fclose ($filepointer);
print"<html><form><input type=\"button\" value=\"Go Back\" onClick=\"history.go(-1);\">";
I have put all my code here
The problem lies with the if statement.
The 2nd for loop works with $maximum but not with string comparisons.
It should print a line if a checkbox is checked for flat in HTML
once the checkbox is checked then the value "flat" will passed to php
if the checkbox is not checked then the value would be null.
these values are passed in the $flat.
$image is a string from txt file wich contains flat1.jpg
therefore, i used
$prop=substr($image,0,4)
in order to compare first 4 characters if they are the same it should print a line from text file.
If it is checked or not it gives always the false statement.