4 Replies - 7043 Views - Last Post: 04 July 2011 - 10:13 AM Rate Topic: -----

#1 jakev383  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 27-May 08

populate HTML dropdown from mysql results

Posted 03 July 2011 - 08:51 PM

I'm trying to populate a HTML dropdown using the results of a mysql query. My DB has a single table "software" and in the table I have field called "version" which does not contain unique data sets. This is the field I'm trying to populate the dropdown with - and since there are multiple entries that have the same number I only want to list an entry once if it has multiple entries, and do it in descending order.

So I have some code written up already, but am not sure how to accomplish the above tasks. Here's what I have so far, but it's not populating the dropdown entries (yes, I know I'm not removing duplicate entries yet - haven't gotten that far):

<?php
include_once "config.php";
include_once "opendb.php";

//let's build the dropdown query
$dropquery = "SELECT `version` FROM testdb ORDER BY `version` DESC";
$dropresult = mysql_query($dropquery) or die(mysql_error());

?>

        <p>
<select name="vers">
<?php
while($row = mysql_fetch_array($dropresult)){
echo "option value=\"".$row['version']."\">".$row["version"]."</option>";
}
?>
        </p>





Any help is appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: populate HTML dropdown from mysql results

#2 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 472
  • Joined: 27-June 10

Re: populate HTML dropdown from mysql results

Posted 03 July 2011 - 09:00 PM

I believe it's because you forgot the first < tag. Look at line 15. The first character you echo should be "<"
Was This Post Helpful? 3
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: populate HTML dropdown from mysql results

Posted 03 July 2011 - 09:15 PM

View Postjakev383, on 04 July 2011 - 03:51 AM, said:

(yes, I know I'm not removing duplicate entries yet - haven't gotten that far):

Hint:
SELECT DISTINCT `version` FROM ...


Was This Post Helpful? 2
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: populate HTML dropdown from mysql results

Posted 03 July 2011 - 11:58 PM

Did you close your select tag.......
        <p>
<select name="vers">
<?php
while($row = mysql_fetch_array($dropresult)){
echo "<option value=\"".$row['version']."\">".$row["version"]."</option>";
}
?>
</select> <!-- Here....


Was This Post Helpful? 0
  • +
  • -

#5 jakev383  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 27-May 08

Re: populate HTML dropdown from mysql results

Posted 04 July 2011 - 10:13 AM

Thanks to all who replied. Everything is working now (even SELECT DISTINCT :bigsmile: )
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1