I am trying to populate a drop down menu with php/mysql. Wouldn’t this be the typical code for something like that? Thanks for any reviews and suggestions for code that actually works. I can’t get this one to work at all.
<?php
$query="SELECT whatever from tablename";
$result=mysql_query($query);
echo ''; // i iadded this line
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
// $whateverid = $row['whateverid'];
// $whatevername = $row['whatevername']; i dont think u need these those vars
echo '' . $row['whatevername']. '';
}
echo '';
?>
Hi, i would do this like this
[php]
$query=“SELECT whatever from tablename”;
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result)) {
$whateverid = $row['whateverid'];
$whatevername = $row['whatevername'];
# the .= appends to the string so if there is more than one option they will all be added to the variable drop down
$dropdown .= '<option value="' . $row['whateverid'] . '">' . $row['whatevername']. '</option>';
}
Would you mind helping me with some proper syntax if I wanted to link each item in the dropdown with a hyperlink? Tried several times but don’t quite know where to put the <a href… with the loop happening. Thanks.
This code properly displays the table contents, thank you. However, it won’t send the browser to the corresponding hyperlink when the item is selected from the dropdown menu. Thoughts? Thanks.
[php]<?php
$query=“SELECT * from mytable”;
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{
I have tried several of these types of scripts and codes. I’m sure they all work but I don’t know how to get the ‘on click’ to work or ‘on select’ to work with a hyperlink. At this point I don’t even mind if I have to select from the drop down and then click ‘go’. Anyone care to help with that? At this point I’d like to have the code I shared above be marked to demonstrate how to add a hyperlink to each ‘foreach’ item. Follow? I have placed the link several places in the code and tested but nothing works.
Each hyperlink will be different based on the dropdown menu item selected. How do I make that correspond? My code is here in this thread. Feel free to combine my code to produce an example if you’d like. I’d like to learn how to do this but after two days of search engines and forums, I’m stuck. Thanks.