Get data from database and put in SELECT TAG
I have three select tags (1)Category, (2)Sub-Category, (3)Product Description and I want to fill it with data from database. But what I want is to when I select eg. Office Supplies from the Category on the Sub Category will only display eg. Ballpen, Ruler, Notebook and when I select eg. Ballpen on the Product Description will only display the description of the Ballpen. Btw I had created some code made from PHP but it only fills the select tags. I hope someone will help me. This is for out Thesis. :)
<html>
<head>
<title>Test Select</title>
</head>
<body>
<?php
$query = "SELECT DISTINCT(`product_cate`) FROM `tbl_product` ";
$result = mysql_query($query);
?>
Category:
<select id="select1">
<option></option>
<?php while($data = mysql_fetch_array($result)){
$displayData = $data['product_cate'];
?>
<option value="<?php echo $displayData;?>"><?php echo $displayData; ?></option>
<?php } ?>
</select>
<?php
$query2 = "SELECT DISTINCT(`product_sub`) FROM `tbl_product`";
$result2 = mysql_query($query2);
?>
Sub Category:
<select id="select2">
<option></option>
<?php while($data2 = mysql_fetch_array($result2)){
$displayData2 = $data2['product_sub'];
?>
<option value="<?php echo $displayData2;?>"><?php echo $displayData2;?></option>
<?php }?>
</select>
<?php
$query3 = "SELECT DISTINCT(`product_desc`) FROM `tbl_product`";
$result3 = mysql_query($query3);
?>
Product Description:
<select id="select3">
<option></option>
<?php while($data3 = mysql_fetch_array($result3)){
$displayData3 = $data3['product_desc'];
?>
<option value="<?php echo $displayData3;?>"><?php echo $displayData3;?></option>
<?php }?>
</select>
</body>
</html>
php mysql select
add a comment |
I have three select tags (1)Category, (2)Sub-Category, (3)Product Description and I want to fill it with data from database. But what I want is to when I select eg. Office Supplies from the Category on the Sub Category will only display eg. Ballpen, Ruler, Notebook and when I select eg. Ballpen on the Product Description will only display the description of the Ballpen. Btw I had created some code made from PHP but it only fills the select tags. I hope someone will help me. This is for out Thesis. :)
<html>
<head>
<title>Test Select</title>
</head>
<body>
<?php
$query = "SELECT DISTINCT(`product_cate`) FROM `tbl_product` ";
$result = mysql_query($query);
?>
Category:
<select id="select1">
<option></option>
<?php while($data = mysql_fetch_array($result)){
$displayData = $data['product_cate'];
?>
<option value="<?php echo $displayData;?>"><?php echo $displayData; ?></option>
<?php } ?>
</select>
<?php
$query2 = "SELECT DISTINCT(`product_sub`) FROM `tbl_product`";
$result2 = mysql_query($query2);
?>
Sub Category:
<select id="select2">
<option></option>
<?php while($data2 = mysql_fetch_array($result2)){
$displayData2 = $data2['product_sub'];
?>
<option value="<?php echo $displayData2;?>"><?php echo $displayData2;?></option>
<?php }?>
</select>
<?php
$query3 = "SELECT DISTINCT(`product_desc`) FROM `tbl_product`";
$result3 = mysql_query($query3);
?>
Product Description:
<select id="select3">
<option></option>
<?php while($data3 = mysql_fetch_array($result3)){
$displayData3 = $data3['product_desc'];
?>
<option value="<?php echo $displayData3;?>"><?php echo $displayData3;?></option>
<?php }?>
</select>
</body>
</html>
php mysql select
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
1
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14
add a comment |
I have three select tags (1)Category, (2)Sub-Category, (3)Product Description and I want to fill it with data from database. But what I want is to when I select eg. Office Supplies from the Category on the Sub Category will only display eg. Ballpen, Ruler, Notebook and when I select eg. Ballpen on the Product Description will only display the description of the Ballpen. Btw I had created some code made from PHP but it only fills the select tags. I hope someone will help me. This is for out Thesis. :)
<html>
<head>
<title>Test Select</title>
</head>
<body>
<?php
$query = "SELECT DISTINCT(`product_cate`) FROM `tbl_product` ";
$result = mysql_query($query);
?>
Category:
<select id="select1">
<option></option>
<?php while($data = mysql_fetch_array($result)){
$displayData = $data['product_cate'];
?>
<option value="<?php echo $displayData;?>"><?php echo $displayData; ?></option>
<?php } ?>
</select>
<?php
$query2 = "SELECT DISTINCT(`product_sub`) FROM `tbl_product`";
$result2 = mysql_query($query2);
?>
Sub Category:
<select id="select2">
<option></option>
<?php while($data2 = mysql_fetch_array($result2)){
$displayData2 = $data2['product_sub'];
?>
<option value="<?php echo $displayData2;?>"><?php echo $displayData2;?></option>
<?php }?>
</select>
<?php
$query3 = "SELECT DISTINCT(`product_desc`) FROM `tbl_product`";
$result3 = mysql_query($query3);
?>
Product Description:
<select id="select3">
<option></option>
<?php while($data3 = mysql_fetch_array($result3)){
$displayData3 = $data3['product_desc'];
?>
<option value="<?php echo $displayData3;?>"><?php echo $displayData3;?></option>
<?php }?>
</select>
</body>
</html>
php mysql select
I have three select tags (1)Category, (2)Sub-Category, (3)Product Description and I want to fill it with data from database. But what I want is to when I select eg. Office Supplies from the Category on the Sub Category will only display eg. Ballpen, Ruler, Notebook and when I select eg. Ballpen on the Product Description will only display the description of the Ballpen. Btw I had created some code made from PHP but it only fills the select tags. I hope someone will help me. This is for out Thesis. :)
<html>
<head>
<title>Test Select</title>
</head>
<body>
<?php
$query = "SELECT DISTINCT(`product_cate`) FROM `tbl_product` ";
$result = mysql_query($query);
?>
Category:
<select id="select1">
<option></option>
<?php while($data = mysql_fetch_array($result)){
$displayData = $data['product_cate'];
?>
<option value="<?php echo $displayData;?>"><?php echo $displayData; ?></option>
<?php } ?>
</select>
<?php
$query2 = "SELECT DISTINCT(`product_sub`) FROM `tbl_product`";
$result2 = mysql_query($query2);
?>
Sub Category:
<select id="select2">
<option></option>
<?php while($data2 = mysql_fetch_array($result2)){
$displayData2 = $data2['product_sub'];
?>
<option value="<?php echo $displayData2;?>"><?php echo $displayData2;?></option>
<?php }?>
</select>
<?php
$query3 = "SELECT DISTINCT(`product_desc`) FROM `tbl_product`";
$result3 = mysql_query($query3);
?>
Product Description:
<select id="select3">
<option></option>
<?php while($data3 = mysql_fetch_array($result3)){
$displayData3 = $data3['product_desc'];
?>
<option value="<?php echo $displayData3;?>"><?php echo $displayData3;?></option>
<?php }?>
</select>
</body>
</html>
php mysql select
php mysql select
asked Oct 3 '13 at 14:43
Jill RoseJill Rose
616
616
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
1
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14
add a comment |
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
1
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
1
1
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14
add a comment |
2 Answers
2
active
oldest
votes
General guide on the path to take would be to use jquery. Basically what will happen is that you'll load the first select ie Category. When the user selects a category, the change should fire up an ajax call to query the db and get sub directories from the category id posted. the call returns the sub category as json which you'll put in the select box. same plan for the product description
This can be a starting point and follow up from there:
jQuery dropdown dependent
Lots of similar questions here
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
You can just link options with an other attribute for example :
<select class="cat"><option>Category<option><select>
<select class="sub_cat"><option data-cat="Category">Sub-Category<option><select>
after that use can use javascript to hide unwanted categories for example (with jquery) :
$('.cat').change(function() {
$('.sub_cat option:not([data-cat="Category"])').hide();
});
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19162192%2fget-data-from-database-and-put-in-select-tag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
General guide on the path to take would be to use jquery. Basically what will happen is that you'll load the first select ie Category. When the user selects a category, the change should fire up an ajax call to query the db and get sub directories from the category id posted. the call returns the sub category as json which you'll put in the select box. same plan for the product description
This can be a starting point and follow up from there:
jQuery dropdown dependent
Lots of similar questions here
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
General guide on the path to take would be to use jquery. Basically what will happen is that you'll load the first select ie Category. When the user selects a category, the change should fire up an ajax call to query the db and get sub directories from the category id posted. the call returns the sub category as json which you'll put in the select box. same plan for the product description
This can be a starting point and follow up from there:
jQuery dropdown dependent
Lots of similar questions here
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
General guide on the path to take would be to use jquery. Basically what will happen is that you'll load the first select ie Category. When the user selects a category, the change should fire up an ajax call to query the db and get sub directories from the category id posted. the call returns the sub category as json which you'll put in the select box. same plan for the product description
This can be a starting point and follow up from there:
jQuery dropdown dependent
Lots of similar questions here
General guide on the path to take would be to use jquery. Basically what will happen is that you'll load the first select ie Category. When the user selects a category, the change should fire up an ajax call to query the db and get sub directories from the category id posted. the call returns the sub category as json which you'll put in the select box. same plan for the product description
This can be a starting point and follow up from there:
jQuery dropdown dependent
Lots of similar questions here
edited May 23 '17 at 12:23
Community♦
11
11
answered Oct 3 '13 at 14:55
Mohamed OmarMohamed Omar
177111
177111
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
Ok thanks for your help! :*
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
You can just link options with an other attribute for example :
<select class="cat"><option>Category<option><select>
<select class="sub_cat"><option data-cat="Category">Sub-Category<option><select>
after that use can use javascript to hide unwanted categories for example (with jquery) :
$('.cat').change(function() {
$('.sub_cat option:not([data-cat="Category"])').hide();
});
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
You can just link options with an other attribute for example :
<select class="cat"><option>Category<option><select>
<select class="sub_cat"><option data-cat="Category">Sub-Category<option><select>
after that use can use javascript to hide unwanted categories for example (with jquery) :
$('.cat').change(function() {
$('.sub_cat option:not([data-cat="Category"])').hide();
});
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
You can just link options with an other attribute for example :
<select class="cat"><option>Category<option><select>
<select class="sub_cat"><option data-cat="Category">Sub-Category<option><select>
after that use can use javascript to hide unwanted categories for example (with jquery) :
$('.cat').change(function() {
$('.sub_cat option:not([data-cat="Category"])').hide();
});
You can just link options with an other attribute for example :
<select class="cat"><option>Category<option><select>
<select class="sub_cat"><option data-cat="Category">Sub-Category<option><select>
after that use can use javascript to hide unwanted categories for example (with jquery) :
$('.cat').change(function() {
$('.sub_cat option:not([data-cat="Category"])').hide();
});
answered Oct 3 '13 at 15:00
SiduxSidux
4721413
4721413
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
Thanks for your help. :D
– Jill Rose
Oct 3 '13 at 15:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19162192%2fget-data-from-database-and-put-in-select-tag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
it's dirty ! :)
– Sidux
Oct 3 '13 at 14:49
why don't you just help me? Please. :)
– Jill Rose
Oct 3 '13 at 14:51
1
I think you are trying to do something like this: yourinspirationweb.com/en/… you might want to make use of jQuery to create a "chained" select/dropdown.
– Maximus2012
Oct 3 '13 at 14:53
Thanks for the link @Maximus2012! That is what i'm looking for. :*
– Jill Rose
Oct 3 '13 at 15:14