Hi


I have some code that I have written that pulls out data from a simple database into a dropdown menu.

<?php
mysql_connect('localhost' , 'databasename', 'password');
mysql_select_db('databasename');
$result=mysql_query("SELECT * FROM Persons");
if(mysql_num_rows($result)>0)
{
?>
<select name="Persons">
<?php
while($rows=mysql_fetch_array($result)){
?>
<option value="<?php echo $rows; ?>"> <?php echo $rows; ?></option>
<?php
}
?>
</select>
<?php
}


I would like to update this to a jump menu so that if one of the items of data is selected the user is taken to a page showing all the data from the database about that record.

So I need a form script and a results page please....

All help appreciated.

Many thanks
Steve

Member Avatar for diafol

that's probably javascript Steve.

Thank you - I've had a play with that today, but can't seem to get it working at all. eg. I'm not getting the user to be sent to the next page of information about the item they selected in the menu.....

I assume this must be a fairly frequently asked question, but I can't see any examples on the site here anywhere?

All help appreciated!

Member Avatar for diafol

if you want a simple sol:

<script>
function jump(param){
    var indx  = param.selectedIndex;
    var selVal = param.options[indx].value;
    var url  = selVal + '.php';
    window.location.href = url;
    return true;
}
</script>

...

<select name="myselect" onchange="jump(this.form.myselect);">
  <option value="index">Home</option>
  <option value="profile">User Profile</option>
  <option value="contact">Contact Us</option>
</select>

not tested

Thanks, but I'm unsure how this fits in with my code and how to integrate the two...

Member Avatar for diafol

The value in tje optipn ips the first part of the page you want to direcct to

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.