473,624 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass OR assign a variable to a drop down menu in php.

14 New Member
Hi!! I know the question look weird but this is what I want to do.

I have to dropdown witch I pass an sql query to populate it. my problem is I really don't know how to pass the value to my search.php

you can made a test by going here

http://www.scale24-25.com/search_form.php

and chose 1/24 from the first drop down, nissan from the second and put 24161 in the text field. clic submit and VOILA... the missing info are the scale and the vehicule manufacture.. because variables are not assign to the dropdown. so HOW I can do that??? and how my code will change in the search.php??
this is my form...


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include_once("db_connection.php");
  3. ?>
  4.  
  5.   <html>  
  6.    <head>  
  7.      <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1">   
  8.     <title>Search  engine</title>  
  9.    </head>  
  10.    <p><body>
  11.  
  12.    <table width="920" border="0">
  13.   <tr>
  14.     <td width="524"><p class="style5"><br />
  15.  
  16.      <table width="920" border="0"><tr><td width="39" align="right"><table width="920" border="0">
  17.        <tr>
  18.          <td><?php // start of dropdown
  19.  
  20. $sql = mysql_query("SELECT DISTINCT scale FROM kit ");
  21. $options = '';
  22.  
  23. echo '<select scale="scale"><option>Scale</option>';
  24.  
  25. while($row = mysql_fetch_array($sql)) {
  26. $thing = $row['scale'];
  27. echo '<option>'.$thing.'</option>';
  28. }
  29. echo '</select>';
  30. // end of dropdown ///?></td>
  31.          <td><div align="left">
  32.            <?php        //  start of drop down  ///
  33.  
  34. $sql = mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel");
  35. $options = '';
  36.  
  37. echo '<select manufacturer_reel="manufacturer_reel"><option>Reel manufacturer</option>';
  38.  
  39. while($row = mysql_fetch_array($sql)) {
  40. $thing = $row['manufacturer_reel'];
  41. echo '<option>'.$thing.'</option>';
  42. }
  43. echo '</select>';
  44. // end of dropdown ///?>
  45.          </div></td>
  46.  
  47.          </tr>
  48.  
  49.        <tr>
  50.          <td colspan="2"><h1 align="center">Model kit database</h1>
  51.              <p align="center">You  may search either by vehicule's  year of fabrication , kit manufacturer or kit number*</p>
  52.            <form  method="post" action="search.php?go"  id="searchform">
  53.                <div align="center">
  54.                  <input  type="text" name="name" />
  55.                  <input  type="submit" name="submit" value="Search" />
  56.                </div>
  57.            </form></td>
  58.        </tr>
  59.      </table></td>
  60.       </table>
  61.      <br>
  62.      <table width="920" border="0">
  63.        <tr>
  64.          <td><h4 align="center"><strong>*  don't put any hyphen &quot; - &quot; in the kit number.
  65.          Ex: usually revell number are 85-2654. here put 852654</strong></h4>
  66.          </td>
  67.        </tr>
  68.      </table>
THIS IS THE SEARCH.PHP

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include_once("db_connection.php");
  4.    if(isset($_POST['submit'])){   
  5.    if(isset($_GET['go'])){   
  6.    if(preg_match("/^[  a-zA-Z0-9]+/", $_POST['name'])){   
  7.    $name=$_POST['name'];   
  8.  
  9.      //-query  the database table for the post field  
  10.    $sql="SELECT  kit_id, kit_number, kit_name, description, manufacturer_kit, engine_detail, year_prod_kit, year_prod_reel, image_id, image_id1, image_id2  FROM kit WHERE kit_number LIKE '%" . $name ."%' OR kit_name LIKE '%" . $name .  "%' OR description LIKE '%" . $name .  "%' OR manufacturer_kit LIKE '%" . $name .  "%' OR year_prod_reel LIKE '%" . $name ."%'";  
  11.  
  12.  
  13.   //-run  the query against the mysql query function   
  14.    $result=mysql_query($sql);  
  15.  
  16.   //-make the header of the table   
  17.  
  18.    echo "  <table align=center width=\"1255\" border=\"\">\n";
  19.    echo "    <tr>\n";
  20.    echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";        
  21.    echo"  <td nowrap align=center width='55'>    scale \n";        
  22.    echo"  <td nowrap align=center width='90'>    kit number \n";        
  23.    echo"  <td nowrap align=center width='290'>    kit name \n";        
  24.    echo"  <td nowrap align=center width='400'>    description \n";
  25.    echo"  <td nowrap align=center width='95'>    vehicule manufacturer \n";
  26.    echo"  <td nowrap align=center width='75'>    year of reel production of car \n";        
  27.    echo"  <td nowrap align=center width='75'>    complete engine detail\n";        
  28.    echo"  <td nowrap align=center width='75'>    Select Picture to get bigger\n";
  29.    echo"  <td nowrap align=center width='75'>    instruction sheet\n";
  30.    echo"  <td nowrap align=center width='50'>    box contain\n";
  31.    echo "    <tr>\n";
  32.  
  33.    //-create  while loop and loop through result set   
  34.    while($row=mysql_fetch_array($result)){   
  35.          $description  =$row['description'];   
  36.          $manufacturer_kit=$row['manufacturer_kit'];   
  37.          $kit_id=$row['kit_id']; 
  38.          $kit_number=$row['kit_number'];
  39.          $kit_name=$row['kit_name'];
  40.          $engine_detail=$row['engine_detail'];
  41.          $year_prod_reel=$row['year_prod_reel'];
  42.          $image_id=$row['image_id'];
  43.          $image_id1=$row['image_id1'];
  44.          $image_id2=$row['image_id2'];
  45.  
  46.  
  47.  
  48.    //-create  table of item during he while loop
  49.  
  50. echo "  <table align=center width=\"1255\" border=\"\">\n";           
  51. echo"  <td nowrap align=center width='95'>  $manufacturer_kit  \n";        
  52. echo"  <td nowrap align=center width='90'>    $kit_number \n";        
  53. echo"  <td nowrap align=center width='290'>    $kit_name \n";        
  54. echo"  <td nowrap width='400'>    $description \n";        
  55. echo"  <td nowrap align=center width='75'>    $year_prod_reel \n";        
  56. echo"  <td nowrap align=center width='75'>    $engine_detail \n";    
  57. echo"  <td nowrap width='75'> <a href=".$image_id.">   <img src='".$image_id."' width='75' height='50' border='0'/>";
  58. 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'/>";
  59. 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'/>";
  60. echo "    </tr>\n";
  61. echo "    </table>\n"; 
  62. echo "    </tr>\n";
  63. echo "    </table>\n";
  64.  
  65.  
  66.    }   
  67.    }  
  68.    else{   
  69.    echo  "<p>Please enter a search query</p>";   
  70.    }   
  71.    }   
  72.    }
  73.  ?>  
THASNK YOU VERY MUCH FOR YOUR HELP

sebastien
Jul 6 '10 #1
2 2186
chazzy69
196 New Member
Not sure if this will help but i found when working with .php, mysql and html at the same time its usually easy to retrieve all information from mysql database before trying to display.

for example set it up like this(note this is not the full code you need) -

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //connect to your database here
  3. //then retrieve all varibles you will need
  4.  
  5. $Var[$i] = mysql_query($query,$connection)
  6. ?>
  7. <html>
  8. <head>
  9. </head>
  10. <body>
  11. <select size="1" name="optionbox">
  12. <option value="1"><?php $var[0]?></option><option value="2"><?php $var[1]?></option>
  13. <option value="3"><?php $var[2]?></option>
  14. <option value="4"><?php $var[3]?></option>
  15. <option value="5"><?php $var[4]?></option>
  16. <option value="6"><?php $var[5]?></option>
  17. <option value="7"><?php $var[7]?></option></select>
  18. </body>
  19. </html>
  20.  
I threw in an example of a drop down box with an example varible standing in for a static value.

Personally i think its better to run all .php before a page fully loads if possible to reduce loading times otherwise everytime someone chooses a different option on your drop down box your going to make another connection to you database.

Hope this helps
Jul 6 '10 #2
TheServant
1,168 Recognized Expert Top Contributor
I haven't looked through that thoroughly, but it looks like you're not including the two dropdowns (scale and manufacturer_re el) within your form which only starts on line 52. Also, you have:
Expand|Select|Wrap|Line Numbers
  1. <select manufacturer_reel="manufacturer_reel">
  2. <select scale="scale">
That is not good HTML and it should be:
Expand|Select|Wrap|Line Numbers
  1. <select name="manufacturer_reel">
  2. <select name="scale">
I am not sure if that works (I have never tried it), but I doubt it will and it is important to understand why.
Jul 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3041
by: scaredemz | last post by:
hi, so i'm creating a dynamic drop-down menu. the menu and the text show up fine in IE but only the drop-down shows in Firefox without the menu text. Below is the fxn code. help pls. function DropDownHelper(menuArray, top, left, height) { var currItem = new String(); var item; var idStr;
8
7451
by: barbarowa | last post by:
I've coded a script to populate a drop down menu from a database but I can't seem to get the PHP script to pass the selected item. The database only has two fields, ID and ITEM. I want the user to be able to see all the choices and pick one. This choice would then be used to update another database. The drop down menu populates correctly. When I test for the variable being passed, nothing is showing up. Here is the code: <?php
19
258982
by: mart2006 | last post by:
I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters what is shown in the dynamic menu. For example, the first menu has three cities London, Paris, New York. If I choose London it populates the second menu with people from London. Here is the code I have for my dynamic menu <td valign=top><strong>Name:</strong></td> <td>...
4
2178
by: Enrika | last post by:
Greetings! I'm working on a CSS drop-down menu, which, to my surprise, is actually working, more-or-less, in both IE *and* Firefox (and Netscape). But there are two changes that I want to make that I just can't figure out how to do. The first is to make the submenu wider than the top menu. Currently, if the text of the submenu doesn't fit within the width of the menu item, the submenu item height increases to accomodate the entire text....
1
2853
by: phpnewb | last post by:
Hi, I know i'm doing it wrong, but I'm using a while loop right now to create several instances of a drop down menu. It gives me undesirable results. Can you tell me the right way to do it. Below are a bit of information on what i did if you want t read it. When I choose select an option in the drop down menu and hit submit, I increase a counter, and a 2nd loop generates a second drop down menu with the same options. This is exactly what...
3
1818
by: Marc | last post by:
Anyone know how to add a drop down menu to a button that will appear when you right click the mouse?
2
3061
by: ponyeyes | last post by:
Hi There, I am a bit of a newbie to PHP programming and I would like to know how I can place a selected drop down option into a PHP variable and then produce an sql query which incorporates this variable. I have created a dynamic drop down menu that populates itself with data from a MySQL table. I now want it to populate a second drop-down menu with relevant options from my database, based upon a query using a variable. For example........
2
5247
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu, but I am unable to store a variable for it. Here is a rough copy of what I am making: <html> <head> <title>Add New MySQL User</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
4
9285
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me if it works, and if it does not, tell me why it does not work. Thanks.
10
57030
by: mart2006 | last post by:
Hi, I'm fairly new to PHP and I've created a dynamic drop down menu that populates itself with data from a MySQL table. What I would like to do is create a non dynamic drop down menu that alters what is shown in the dynamic menu. For example, the first menu has three cities London, Paris, New York. If I choose London it populates the second menu with people from London. Here is the code I have for my dynamic menu <td...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.