Hello everyone,
I have a small problem in my php script
In my select I have two types of request, "Show all" that displays all the marks and the other as a parameter query that takes the brand chosen.
When I chose to deal with brand it works, and when I selected after dealing with "Show all"
It works.
What I wanted to make is that the first time, "show all" market will be
Here's the script:
<?php
require_once("connect.php");
connect();
$sql = 'SELECT DISTINCT make FROM `cars` ORDER BY make ';
$req = mysql_query($sql) or die ("erreur2");
$num_ligne = mysql_num_rows($req);
while($row = mysql_fetch_array($req) )
{
$make[] = $row['make'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post" id="formulaire">
<STRONG> Sélectionner Make : </STRONG>
<select selected="show all" name="make" id="make" onchange="document.forms['formulaire'].submit();">
<option ><?php echo "show all" ?></option>
<?php for($i=0;$i<$num_ligne;$i++){ ?>
<option value="<?php echo($make[$i]) ?>"
<?php echo((isset($idr) && $idr == $make[$i])?" selected=\"selected\"":null) ?>> <?php echo $make[$i] ?>
</option>
<?php } ?>
</select>
<?php
if($idr != "show all") {
mysql_free_result($req);
if(isset($idr) && $idr != -1){
$select = 'SELECT * FROM cars WHERE `make` = "'. $idr .'" ORDER BY colour';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);
// si on a récupéré un résultat on l'affiche.
require_once("afficher_cars.php");
}
}
else{
$select = 'SELECT * FROM cars ORDER BY car_id ';
$result = mysql_query($select) or die ('Erreur : '.mysql_error() );
$total = mysql_num_rows($result);
// si on a récupéré un résultat on l'affiche.
require_once("afficher_cars.php");
}//fin condition
?>
</form>
</body>
</html>