PHP Input Type With Dropdown

Hi All,

I’m a beginner to PHP and am having trouble with a Dropdown using PHP and SQL.

This is what I have:

$result = mysql_query($sql);
echo " <form id='myForm' action='https://mywebsite.com/forum/index.php/'> ";
echo ' <select name="/"> ';
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['field_181'] ."'>" . $row['field_181'] ." - " . $row['COUNT(field_181)'] . " Events </option>";
}
echo " </select> ";
echo " <br><br> ";
echo " <input type='submit'> ";
echo '<input type="hidden" name="-bowling-tournaments" > ';
echo " </form> ";

So this code is working in that it’s properly displaying the Dropdown items in my database. The problem is that when I click submit, it’s bringing me to this URL: https://mywebsite.com/forum/index.php?/=New%2BYork&-bowling-tournaments=

The URL it SHOULD be bringing me to is https://mywebsite.com/forum/index.php?/new-york-bowling-tournaments/

But I don’t know how to fix it. Can anyone please assist?

If the format can be something like your_page?bowling-tournaments=New York, then you could use a select/option menu for this. For the specific format you have shown, you would need to use a dropdown menu, where you would build the specific URLs, then click on the desired one. This is done with just HTML/CSS. See this example - How To Create a Hoverable Dropdown Menu

Yes, I know how to build a dropdown using HTML. I need to use PHP for this as I’m also using SQL in the code to pull information from the database. I need the PHP dropdown to link to the correct URL based on which option I choose. The URL changes for each option as outlined in my OP.

You would dynamically build the html dropdown, using php, from the information you query from the database.

Assuming that the appearance of the dropdown that I linked to above is acceptable, the code to produce the dynamic links in the dropdown would be -

<div class="dropdown">
  <button class="dropbtn">Select City</button>
  <div class="dropdown-content">
	<?php
	while ($row = mysql_fetch_array($result)) {
		echo "<a href='https://mywebsite.com/forum/index.php?/".str_replace(' ','-',$row['field_181'])."-bowling-tournaments/'>{$row['field_181']}</a>";
	}
	?>
  </div>
</div>

This is great and it worked. I was able to maneuver your code into my own to make it work.
One last question - how do I make it so it’s just a regular dropdown and not that hover dropdown?

How To Create a Dropdown Menu With CSS and JavaScript.

Sponsor our Newsletter | Privacy Policy | Terms of Service