By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Dropdown in php

P: 4
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
Share this Question
Share on Google+
5 Replies


omerbutt
100+
P: 638
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

P: 4
I have tried this and in the box i get ".$row['moduleID']."

Regards Ruth
Dec 4 '11 #3

100+
P: 1,059
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

P: 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

100+
P: 1,059
please read the documentation about drop down searching on google
Dec 4 '11 #6

Post your reply

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