473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dropdown in php

i am trying to use a drop down in php based on the results i returned in the query. at the moment i have three items in my database so the form is displaying correctly bu the drop down option is not. it returns $row['$results']

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   $sql = "SELECT moduleID FROM module";
  3.  
  4.                     $stmt = $conn->prepare($sql);
  5.                 try {
  6.                     $stmt->execute();
  7.                     $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  8.  
  9.                     if (!$results){ // check we have some results
  10.                         echo "No modules Available to rank <br />";
  11.                     }
  12.                     else{    //generate form
  13.  
  14.                         foreach ($results as $row){
  15.  
  16.                         ?>
  17.                            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
  18.                             <label for="search">Rate:</label>
  19.                             <select name"modIDDropdown" value="moduleID">
  20.                              echo "<option>$row['$results']</option>"
  21.                             </select>
  22.                             <input type="submit" name="submit" id="submit" />
  23.                                </form>
  24.                                <?php
  25.                         }
  26.  
  27.                     }
  28.                 } catch ( PDOException $e ) {
  29.                     echo "Query failed: " . $e->getMessage();
  30.                 }
  31. ?>
Dec 4 '11 #1
5 1587
omerbutt
638 512MB
hi
chnage
Expand|Select|Wrap|Line Numbers
  1. echo "<option>$row['$results']</option>"
to the following as you are returning the assoc array
Expand|Select|Wrap|Line Numbers
  1. echo "<option>".$row['NAME_OF_THE_TABLE_FIELD']."</option>";
  2.  
regards,
Omer Aslam
Dec 4 '11 #2
I have tried this and in the box i get ".$row['moduleID']."

Regards Ruth
Dec 4 '11 #3
johny10151981
1,059 1GB
I dont see any thing right in your select object.
Expand|Select|Wrap|Line Numbers
  1. <select name"modIDDropdown" value="moduleID">
  2. echo "<option>$row['$results']</option>"
  3. </select>
  4.  
rewrite it according below:
Expand|Select|Wrap|Line Numbers
  1. <select name="modIDDropdown" >
  2. <?php
  3. echo "<option value='".$row[$results]."'>".$row[$results]."</option>";
  4. ?>
  5. </select>
  6.  
Dec 4 '11 #4
thank you as this work now but i would like all the drop downs to contain all the same values. for example there is now three modules and i want to rank them so i would want all three values in each drop down how to i go about that?
Dec 4 '11 #5
johny10151981
1,059 1GB
please read the documentation about drop down searching on google
Dec 4 '11 #6

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

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
0
by: Toonman | last post by:
I have a webpage with a <form> consisting of a large table grid of dropdown lists used to make changes in a database. Some of these dropdown lists have the same value. I'm trying to make it so...
6
by: Rey | last post by:
Howdy, all. Appreciate your help. Have a one to many relation between a client and visit table. In the visit subform, I have a visittype and counselor field which are comboboxes. If I set...
13
by: melih.onvural | last post by:
Group, I'm having a tough time understanding some of the previous posts on this topic so I wanted to write what I've tried and hope that you can help me troubleshoot. I have a dropdown populated...
2
by: 23s | last post by:
I have a dropdown bound to a dataview. The binding assigns the dropdown with a SelectedIndex of 0. There is a msgbox in the SelectedIndexChanged event that displays the SelectedIndex property....
5
by: Gil | last post by:
Is there a way to tell if a combbox is in dropdown mode. I tried and if statement combobox.dropdown = true but i get an error. dropwndown function doesnt store if its true or false what i am...
3
by: CSharpguy | last post by:
I'm trying to populate a drop down with dates from a data field in my data base but I want the format like MM/dd/yyyy instead of 1/1/2006 12:00 PM How can I my date to show as 1/1/2006? I'm...
3
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown listboxes where the first is populated in page load and...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.