Hi everybody, Im new here so a little introduction. Iam 30 years, very new to the website developing and php/mysql business and thats why I had to post a question on your forum.
I am developing this website for people to find a particular type of car.
It's something like this (the original website has ofcourse much more choices but to make it easier to read) --> the options:
1. brand of the car: Audi, Opel, BMW
2. color: red, green, black
3. year the car was built: 1990, 1991, 1992
I'm using php and html.
Bwlow is the code + form I'm using which works great (although some say there are a lot of errors and wrong coding, for some reason the code works fine even with error-detection on) . I can make a selection, and when I press search, the results are displayed on results.php using Lightbox (very nice)
My question is: I now have only 1 option I can select. Bij adding size=1 multiple> and [] to for example <select name="brand"> to make it look like <select name="brand[]" size=1 multiple>
I can select multiple options. But when I press the search button I get the message "no selection was made". But I did make a selection. When I remove [] and keep the addition size=1 multiple then I can select multiple options but when I press the search button, the result.php page only dusplays the results of the last selection. For example I select Audi and Opel then the result page only displays Opel pictures. I dont understand what I'm doing wrong. I hope you do.
Thank you very much already!!!!
<?php
$brands = array("audi","bmw","opel");
$colors = array("red","groen","black",);
if($_SERVER['REQUEST_METHOD'] == 'POST' ) {
$where = array();
if (isset($_POST["brand"]) && in_array($_POST["brand"],$brands)) {
$where[] = "BRAND='".$_POST["brand"]."'";
}
if (isset($_POST["color"]) && in_array($_POST["color"],$colors)) {
$where[] = "COLOR='".$_POST["kleur"]."'";
}
if (isset($_POST["year"]) && preg_match("/^(19|20)\d\d$/i", $_POST["year"])) {
$where[] = "YEAR='".$_POST["year"]."'";
}
if (count($where)==0) {
echo "no selection was made.";
} else {
$query = "select ID, BRAND, COLOR, YEAR from catalog_table WHERE ".implode(" AND ",$where);
if ($result = mysql_query($query)) {
if (mysql_num_rows($result)<>0) {
while ( $row = mysql_fetch_assoc ( $result ) ) {
echo $row["BRAND"]." - ".$row["COLOR"]." - ".$row["YEAR"]."<br />";
$informationquery = "select INFORMATION from information where Catalog_ID=".$row["ID"];
if ($informationresult = mysql_query($informationquery)) {
if (mysql_num_rows($informationresult)<>0) {
while ( $informationrow = mysql_fetch_assoc ( $informationresult ) ) {
echo $informationrow["INFORMATION"]."<br />";
}
} else {
echo "no information availible<br />";
}
}
$photoquery = "select PHOTO from foto where Catalog_ID=".$row["ID"];
if ($photoresult = mysql_query($photoquery)) {
if (mysql_num_rows($photoresult)<>0) {
while ( $photorow = mysql_fetch_assoc ( $photoresult ) ) {
echo '<a title="' . $row['PHOTO'] . '" href"images/big/' . $row['PHOTObig'] . "' rel="lightbox"><img src="images/thumbs/' . $photorow['PHOTOthumb']."' alt='".$row["BRAND"]." - ".$row["COLOR"]." - ".$row["YEAR"]."' /><br />";
}
} else {
echo "<img src='nophoto.jpg' alt='no photo' /><br />";
}
}
}
} else {
echo "no cars matched your selection.";
}
}
}
}
?>
<hr />
<form method="post" action="result.php">
<select name="brand">
<option selected="selected">Brand</option>
<option><?php echo implode("</option><option>",$brands); ?></option>
</select>
<select name="color">
<option selected="selected">Color</option>
<option><?php echo implode("</option><option>",$colors); ?></option>
</select>
<select name="year">
<option selected="selected">Year</option>
<option>1990</option>
<option>1991</option>
<option>1992</option>
</select>
<input type="submit" value="search" />
</form>