Jump to content

why I can't do multiple selection???


scaleautostyle

Recommended Posts

HELLO... me again...

 

I do my add-on of drop down and everything work NUMBER 1. thanks to kenrbnsn for his help. but I just see something that will be not good for the user.

 

I explain..

 

IF I make a choice in only one dropdown I get my result. but If I make a selection in 2 or more dropdown it doesn't work it will show the first result from the higher dropdown.

 

EX: you select 1/24 in scale and aoshima in manufacturer kit. It will show you everything in 1/24 because this dropdown is before the other one.

 

the order of drop down are:

 

scale

manufacturer_reel

manufacturer_kit

year_prod_reel

 

An other thing if you do a selection that's impossible... EX. you select Honda and 1966 in the year. it will return every honda it will find. but in fact this selection is not valid. no honda 1996 are in the database.

 

here my coding for both file.

 

THE FORM

 

<?php
include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
</head>

<body >
<?php

if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$manufacturer_reel=$_POST['manufacturer_reel'];

$query="select * from kit where  ";

////////// Including manufacturer_reel field search ////
if(strlen($manufacturer_reel) > 0 ){
$query.= " manufacturer_reel='$manufacturer_reel' and "; 
}  
//// End of class field search ///////////

$query=substr($query,0,(strLen($query)-4));

echo $query;
echo "<br><br>";
$nt=mysql_query($query);
echo mysql_error();

// End if form submitted



}else{

echo "<form method=post action='search-keyword.php?go'><input type=hidden name=todo value=search>";


//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT scale FROM kit ORDER BY scale");
echo '<select name="scale"><option>scale</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['scale'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

echo " <br> \n";
echo " <br> \n";
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel");
echo '<select name="manufacturer_reel"><option>Reel manufacturer</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";
//  end of drop down  ///
//  start of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_kit FROM kit ORDER BY manufacturer_kit");
echo '<select name="manufacturer_kit"><option>kit manufacturer</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_kit'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT year_prod_reel FROM kit ORDER BY year_prod_reel");
echo '<select name="year_prod_reel"><option>vehicules year manufactured</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['year_prod_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";

echo "
<br><input type=submit value=Search name='name' action='search-keyword.php?go' >
</form>
";
}


?>







</body>

</html>

 

 

 

and the search-keyword.php

 

 

 

<?php

include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>

</head>

<body >
<?php
if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$name=$_POST['manufacturer_reel'];
$name1=$_POST['manufacturer_kit'];
$name2=$_POST['year_prod_reel'];
$name3=$_POST['scale'];


//-query  the database table for the post field  
   $sql="SELECT  kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, scale, engine_detail, year_prod_kit, year_prod_reel, image_id, image_id1, image_id2  FROM kit WHERE manufacturer_reel LIKE '%" . $name ."%' OR scale LIKE '%" . $name3 ."%' OR year_prod_reel LIKE '%" . $name2 ."%' OR manufacturer_kit LIKE '%" . $name1 ."%'";  


  //-run  the query against the mysql query function   
   $result=mysql_query($sql);  
   
  //-make the header of the table   
   
   echo "  <table align=center width=\"1255\" border=\"\">\n";
   echo "    <tr>\n";
   echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";		
   echo"  <td nowrap align=center width='55'>	scale \n";		
   echo"  <td nowrap align=center width='90'>	kit number \n";		
   echo"  <td nowrap align=center width='290'>	kit name \n";		
   echo"  <td nowrap align=center width='400'>	description \n";
   echo"  <td nowrap align=center width='95'>	vehicule manufacturer \n";
   echo"  <td nowrap align=center width='75'>	year of reel production of car \n";		
   echo"  <td nowrap align=center width='75'>	complete engine detail\n";		
   echo"  <td nowrap align=center width='75'>	Select Picture to get bigger\n";
   echo"  <td nowrap align=center width='75'>	instruction sheet\n";
   echo"  <td nowrap align=center width='50'>	box contain\n";
   echo "    <tr>\n";

   //-create  while loop and loop through result set   
   while($row=mysql_fetch_array($result)){   
         $description  =$row['description'];   
         $manufacturer_kit=$row['manufacturer_kit']; 
	 $scale=$row['scale']; 
	 $manufacturer_reel=$row['manufacturer_reel'];   
         $kit_id=$row['kit_id']; 
	 $kit_number=$row['kit_number'];
	 $kit_name=$row['kit_name'];
	 $engine_detail=$row['engine_detail'];
	 $year_prod_reel=$row['year_prod_reel'];
	 $image_id=$row['image_id'];
	 $image_id1=$row['image_id1'];
	 $image_id2=$row['image_id2'];


	   
   //-create  table of item during he while loop
   
echo "  <table align=center width=\"1255\" border=\"\">\n";		   
echo"  <td nowrap align=center width='95'>  $manufacturer_kit  \n";	
echo"  <td nowrap align=center width='95'>  $scale  \n";
echo"  <td nowrap align=center width='95'>  $manufacturer_reel  \n";	
echo"  <td nowrap align=center width='90'>	$kit_number \n";		
echo"  <td nowrap align=center width='290'>	$kit_name \n";		
echo"  <td nowrap width='400'>	$description \n";		
echo"  <td nowrap align=center width='75'>	$year_prod_reel \n";		
echo"  <td nowrap align=center width='75'>	$engine_detail \n";	
echo"  <td nowrap width='75'> <a href=".$image_id.">   <img src='".$image_id."' width='75' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo"  <td nowrap width='50'> <a href=".$image_id2.">   <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo "    </tr>\n";
echo "    </table>\n"; 
echo "    </tr>\n";
echo "    </table>\n";


   }   
   }  
   else{   
   echo  "<p>Please enter a search query</p>";   
   }   
   
?>  



</body>

</html>

 

 

thanks

 

sebastien

 

Link to comment
Share on other sites

SQL seems fine, it should be selecting anythign that matches at least one down down box.

WHERE manufacturer_reel LIKE '%" . $name ."%' OR scale LIKE '%" . $name3 ."%' OR year_prod_reel LIKE '%" . $name2 ."%' OR manufacturer_kit LIKE '%" . $name1 ."%'"; 

 

If you want it to be specific, change the OR's to AND's.

 

-cb-

Link to comment
Share on other sites

I already change the 3 OR  by 3 AND but the result is nothing. I only get the table header. like it doesn't process the sql query...

 

and with the OR. it look like if I choose a manufacturer and a year. it will gave me everything from this specific manufacturer and also everything will match the year. ????

 

So... what't the solution to this problem ???

 

I dig all around the web and my book to find the solution and right now  :'(

 

thanks for your help

 

sebastien

Link to comment
Share on other sites

I found this. and it's logical but it's not what I want.

 

If I put the AND operator instead of the OR the user have to fill every field to pass the query.

 

but what I want is:

 

the user can fill as many as field he want. more field are filled less result will be shown.

 

I was think doing an if else OR an if elseif statement in my sql aftre the WHERE like: will be good... but HOW can I do that to cover every possibility????

 

let me knw if someone think something.

 

yours

 

sebastien

Link to comment
Share on other sites

You could build the query, where it would combine only the selected parameters.

 

Such as: -UNTESTED

<?php

foreach($_POST as $key => $value) {
$v = strtolower($value);
if($v != 'reel manufacturer' || $v != 'scale' || $v != 'kit manufacturer' || $v != 'vehicules year manufactured') { //This kills the value being passed, if nothing was selected.
	$where[] = $key . ' = \'' . $value . '\'';
}
}

if(!empty($where)) {
$where = implode(' AND ',$where);

$sql = "SELECT * FROM kit WHERE $where ";

$nt = mysql_query($sql);
}
else {
echo 'You need to select at least one parameter!';
}
?>

Link to comment
Share on other sites

I replace the existing sql query by yours. the final result is

 

 

<?php
//-query  the database table for the post field  


foreach($_POST as $key => $value) {$v = strtolower($value);	if($v != 'manufacturer_reel' || $v != 'scale' || $v != 'manufacturer_kit' || $v != 'year_prod_reel') { //This kills the value being passed, if nothing was selected. 

	$where[] = $key . ' = \'' . $value . '\'';	}}if(!empty($where)) {$where = implode(' AND ',$where);$sql = "SELECT * FROM kit WHERE $where ";$nt = mysql_query($sql);}else {echo 'You need to select at least one parameter!';


  //-run  the query against the mysql query function   
   $result=mysql_query($sql);  
   
  //-make the header of the table   
   
   echo "  <table align=center width=\"1340\" border=\"\">\n";
   echo "    <tr>\n";
   echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";		
   echo"  <td nowrap align=center width='55'>	scale \n";		
   echo"  <td nowrap align=center width='90'>	kit number \n";		
   echo"  <td nowrap align=center width='290'>	kit name \n";		
   echo"  <td nowrap align=center width='400'>	description \n";
   echo"  <td nowrap align=center width='125'>	vehicule year \n";		
   echo"  <td nowrap align=center width='80'>	complete engine detail\n";		
   echo"  <td nowrap align=center width='80'>	Select Picture to get bigger\n";
   echo"  <td nowrap align=center width='75'>	instruction sheet\n";
   echo"  <td nowrap align=center width='75'>	box contain\n";
   echo "    <tr>\n";

   //-create  while loop and loop through result set   
   while($row=mysql_fetch_array($result)){   
         $description  =$row['description'];   
         $manufacturer_kit=$row['manufacturer_kit']; 
	 $scale=$row['scale']; 
	 $m

?>

 

If it's what supposed to be I confirm you it doesn't work. it only display the table header.

 

 

yours

 

sebastien

Link to comment
Share on other sites

You need to change the parts in the code jcbones gave you to reflect the default dropdown selection in eachfield. Also, you should have a "value" attribute for each <option> tag.

 

For instance, the way your form is now, your default value for manufacturer_kit is "kit manufacturer".

So, you would change your script to reflect this:

if($v != 'kit manufacturer')

 

You should really use value attributes in your option tags:

<option value="kit manufacturer">Please Choose an Option</option>

 

As you can see using the value attribute allows you to define a seperate "Display" value for the option, you can use ID Numbers in the Value attributes and show the name of that item within the option tags.

 

-cb-

Link to comment
Share on other sites

thank you ChemicalBliss for your explaination.

 

I redo the code base on ehta you say about the value in my option dropdown. also correct as per the original script of jcbones. let see if I understand what you say.

 

 

this the corrected FORM

 

 

<?php
include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
</head>

<body >
<?php

if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$manufacturer_reel=$_POST['manufacturer_reel'];

$query="select * from kit where  ";

////////// Including manufacturer_reel field search ////
if(strlen($manufacturer_reel) > 0 ){
$query.= " manufacturer_reel='$manufacturer_reel' and "; 
}  
//// End of class field search ///////////

$query=substr($query,0,(strLen($query)-4));

echo $query;
echo "<br><br>";
$nt=mysql_query($query);
echo mysql_error();

// End if form submitted



}else{

echo "<form method=post action='search-keyword.php?go'><input type=hidden name=todo value=search>";


//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT scale FROM kit ORDER BY scale");
echo '<select name="scale"><option value="scale">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['scale'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

echo " <br> \n";
echo " <br> \n";
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel");
echo '<select name="manufacturer_reel"><option value="reel manufacturer">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";
//  end of drop down  ///
//  start of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_kit FROM kit ORDER BY manufacturer_kit");
echo '<select name="manufacturer_kit"><option value="kit manufacturer">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_kit'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT year_prod_reel FROM kit ORDER BY year_prod_reel");
echo '<select name="year_prod_reel"><option value="vehicules year manufactured">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['year_prod_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";

echo "
<br><input type=submit value=Search name='name' action='search-keyword.php?go' >
</form>
";
}


?>

 

and this is the corrected SEARCH-KEYORD.php

 

<?php

include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>

</head>

<body >
<?php
if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$name=$_POST['manufacturer_reel'];
$name1=$_POST['manufacturer_kit'];
$name2=$_POST['year_prod_reel'];
$name3=$_POST['scale'];


//-query  the database table for the post field  


foreach($_POST as $key => $value) {$v = strtolower($value);	if($v != 'reel manufacturer' || $v != 'scale' || $v != 'kit manufacturer' || $v != 'vehicules year manufactured') { //This kills the value being passed, if nothing was selected.		

$where[] = $key . ' = \'' . $value . '\'';	}}if(!empty($where)) {$where = implode(' AND ',$where);$sql = "SELECT * FROM kit WHERE $where ";$nt = mysql_query($sql);}else {echo 'You need to select at least one parameter!';}


  //-run  the query against the mysql query function   
   $result=mysql_query($sql);  
   
  //-make the header of the table   
   
   echo "  <table align=center width=\"1340\" border=\"\">\n";
   echo "    <tr>\n";
   echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";		
   echo"  <td nowrap align=center width='55'>	scale \n";		
   echo"  <td nowrap align=center width='90'>	kit number \n";		
   echo"  <td nowrap align=center width='290'>	kit name \n";		
   echo"  <td nowrap align=center width='400'>	description \n";
   echo"  <td nowrap align=center width='125'>	vehicule year \n";		
   echo"  <td nowrap align=center width='80'>	complete engine detail\n";		
   echo"  <td nowrap align=center width='80'>	Select Picture to get bigger\n";
   echo"  <td nowrap align=center width='75'>	instruction sheet\n";
   echo"  <td nowrap align=center width='75'>	box contain\n";
   echo "    <tr>\n";

   //-create  while loop and loop through result set   
   while($row=mysql_fetch_array($result)){   
         $description  =$row['description'];   
         $manufacturer_kit=$row['manufacturer_kit']; 
	 $scale=$row['scale']; 
	 $manufacturer_reel=$row['manufacturer_reel'];   
         $kit_id=$row['kit_id']; 
	 $kit_number=$row['kit_number'];
	 $kit_name=$row['kit_name'];
	 $engine_detail=$row['engine_detail'];
	 $year_prod_reel=$row['year_prod_reel'];
	 $image_id=$row['image_id'];
	 $image_id1=$row['image_id1'];
	 $image_id2=$row['image_id2'];


	   
   //-create  table of item during he while loop
   
echo "  <table align=center width=\"1340\" border=\"\">\n";		   
echo"  <td nowrap align=center width='95'>  $manufacturer_kit  \n";	
echo"  <td nowrap align=center width='55'>  $scale  \n";
echo"  <td nowrap align=center width='90'>	$kit_number \n";		
echo"  <td nowrap align=center width='290'>	$kit_name \n";		
echo"  <td nowrap width='400'>	$description \n";
echo"  <td nowrap align=center width='125'>	$year_prod_reel \n";		
echo"  <td nowrap align=center width='80'>	$engine_detail \n";	
echo"  <td nowrap width='80'> <a href=".$image_id.">   <img src='".$image_id."' width='75' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href=".$image_id2.">   <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo "    </tr>\n";
echo "    </table>\n"; 
echo "    </tr>\n";
echo "    </table>\n";


   }   
   }  
   else{   
   echo  "<p>Please enter a search query</p>";   
   }   
   
?>  

 

if this is the code ...  it's not working EXCEPT if I took a good selection that can be find in the database. EX: 1/24 for scale, Prosche for reel manufacturer, tamiya for kit manufacturer and 1968 for vehicule year.

 

but in the case I put only 3 OR do an error for the year nothing will show up.

 

thanks for help but I have to work a bit more to get it work.

 

yours

 

sebastien

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.