logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Dreamweaver General
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-18-2015, 11:58 PM   #1
theowls
 
Join Date: Feb 2015
Posts: 10
Default Selecting data from a drop down box

Sorry if this has been asked before, did do a search.

I have a drop down box that gets its data from a database, I want the user to select a value from the drop down box which will take them to another page.

Can someone give me a bit of a heads up on this please?

Thanks in advance
theowls is offline   Reply With Quote
Old 06-19-2015, 12:47 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

whats your code so far?
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-19-2015, 01:12 AM   #3
theowls
 
Join Date: Feb 2015
Posts: 10
Default index.php

<?php
include('config.php');
$query_parent = mysqli_query($con,"SELECT * FROM categories") or die("Query failed: ".mysqli_error());
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dependent DropDown List</title>
<style>
form {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 18px;
}
select {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 18px;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$("#parent_cat").change(function() {
$(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
$.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
$("#sub_cat").html(data);
$('#loader').slideUp(200, function() {
$(this).remove();
});
});
});

});
</script>
</head>

<body>
<form method="get">
<label for="category">Cuisine</label>
<select name="parent_cat" id="parent_cat">
<?php while($row = mysqli_fetch_array($query_parent)): ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['category_name']; ?></option>
<?php endwhile; ?>
</select>
<br/><br/>

<label>Restaurant</label>
<select name="sub_cat" id="sub_cat"></select>
</form>
</body>
</html>
theowls is offline   Reply With Quote
Old 06-19-2015, 02:24 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

so you want to add a link to this?
Code:
<option value="<?php echo $row['id']; ?>"><?php echo $row['category_name']; ?></option>
what will the page be to link to. meaning how will it be called?
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-19-2015, 02:36 AM   #5
theowls
 
Join Date: Feb 2015
Posts: 10
Default

Let's say the page will be called indian.php
theowls is offline   Reply With Quote
Old 06-19-2015, 02:44 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

ok as you are creating the link from database it shpouls also be a dynamic name.
example in html
<a href="indian.php"> indian</a>

dynamically it could be
<a href="<php echo $row['category_name']"> <php echo $row['category_name']"></a>

if 'category_name' is the correct data
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-19-2015, 02:46 AM   #7
theowls
 
Join Date: Feb 2015
Posts: 10
Default

thanks for all the trouble in helping me..
theowls is offline   Reply With Quote
Old 06-19-2015, 02:50 AM   #8
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

welcome post back if you have trouble
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 06-20-2015, 03:27 AM   #9
theowls
 
Join Date: Feb 2015
Posts: 10
Default

Hi edbr

Sorry but where in the above code would I position -

<a href="<php echo $row['category_name']"> <php echo $row['category_name']"></a>

as you stated?

Thanks
theowls is offline   Reply With Quote
Old 06-20-2015, 03:48 AM   #10
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

it would be in your option tags but you need to edit to the correct rows form your database as i dont know what they contain, so i was giving you an example.
imn your code you show a <select> containing a while loop for the <option>

using my example ( whics depends on your database data would be

Code:
<select name="parent_cat" id="parent_cat">


<?php while($row = mysqli_fetch_array($query_parent)): ?>

<option><a href="<php echo $row['category_name']"> <php echo $row['category_name']"></a></option>


<?php  } ?>


</select>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:48 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com