Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,970 members, 7,817,848 topics. Date: Saturday, 04 May 2024 at 09:09 PM

How Can I Code This In Php/html? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Code This In Php/html? (4131 Views)

I'm Learning Programming But... How Can I Code (as In ... In Real Life)??? / Running Python Codes In Php / How Do I Code And Configure Smtp To Send Mail In My Script (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Code This In Php/html? by oluagness(m): 3:51am On Dec 10, 2013
Thanking you for your constant help, may God bless us. Please, i want my form to auto generate local government if a state is selected. For example, if lagos state is selected, i want my form to list all the local government in lagos state. Please help.
Re: How Can I Code This In Php/html? by suneepet1: 10:22am On Dec 10, 2013
first crate a table and polulate with state names.now create tables of each state local government while the state name is used as the foreign key for respective local government table .you will understand better if you understad how to create a relational database.
not confortable here cos am typing from my phone
Re: How Can I Code This In Php/html? by ire4me: 12:14pm On Dec 10, 2013
I am facing same issue, hope suneepet1 solution will solve it
Re: How Can I Code This In Php/html? by talk2hb1(m): 12:33pm On Dec 10, 2013
You need basic knowledge of Ajax.
Re: How Can I Code This In Php/html? by oluagness(m): 6:07pm On Dec 10, 2013
talk2hb1: You need basic knowledge of Ajax.
i have basic knowledge of it. What should i do?
Re: How Can I Code This In Php/html? by oluagness(m): 6:13pm On Dec 10, 2013
For every soul that is bailing me out of this problem, problems and difficulties will be far from your household. Please help.
Re: How Can I Code This In Php/html? by robzyone: 7:03pm On Dec 10, 2013
U ve to create a table in ur database with all the states. Each state must have a unique key. Create a table for local govt and link each local govt with the unique key of its state.
U are going to use ajax and php to complete this task. It is necessary you have a knowledge of jquery also. Am using my phone to comment so its not really easy to comment well.
U will need 2 files. The php file where the change will be made on the select button and a php file where u will query db for local govt. It will be beta if u load the states from database straight and include the state uniqueu need to write a jquery function to perform an ajax anytime an action is performed to load d local govts (eg when a user changes d select button). u can now send the state to the php file as post or get to the php file to query the database for lga with the state. On completion echo the display way u want it to work.

Please i am using my mobile now and cant type well but once i get to my system i will upload codes on how it works. Sorry for poor write up and incomplete explanation. In lagos traffic......
Re: How Can I Code This In Php/html? by jboy01(m): 7:13pm On Dec 10, 2013
Pls is javascript or java applet is good choice for the task?
Re: How Can I Code This In Php/html? by robzyone: 7:15pm On Dec 10, 2013
What you need is javascript or jquery
Re: How Can I Code This In Php/html? by EdDave(m): 7:29pm On Dec 10, 2013
Hw abt CSS?
Re: How Can I Code This In Php/html? by robzyone: 8:20pm On Dec 10, 2013
U dont need css to achieve this result. CSS is for design.
Re: How Can I Code This In Php/html? by Nobody: 9:44pm On Dec 10, 2013
First thing your table structure should be

State Table
CREATE TABLE State
(
name VARCHAR(30) PRIMARY KEY
);

CREATE TABLE LGA
(
LGAName VARCHAR(30),
state VARCHAR(30) REFERENCES State (name)
)

I expect you to know how to interact with database using php(Load or Query data).

You need Ajax just because you don't want your page to refresh but i will advice you get the logic of how to implement your problem.

1) Create form that have <select> or drop down list for state and local govt.
2) Populate the state dropdown list with what you have in your database (Let me know if you have no idea how to query database and populate in dropdown list)

3) Without Ajax, you can use onchange of the state drop down list to populate Local govt by getting the selected item. (Without Ajax ur page will refresh but your problem will be solve.) The base practice is to use Ajax (though it's socially constructed) because most sites still use traditional method that refresh the entire page.


Let us know if you are a newbie in php meaning that you can't query database table and populate a combo or dropdown box for more assistance.
Re: How Can I Code This In Php/html? by robzyone: 10:07pm On Dec 10, 2013
Nekon J: First thing your table structure should be

State Table
CREATE TABLE State
(
name VARCHAR(30) PRIMARY KEY
);

CREATE TABLE LGA
(
LGAName VARCHAR(30),
state VARCHAR(30) REFERENCES State (name)
)

I expect you to know how to interact with database using php(Load or Query data).

You need Ajax just because you don't want your page to refresh but i will advice you get the logic of how to implement your problem.

1) Create form that have <select> or drop down list for state and local govt.
2) Populate the state dropdown list with what you have in your database (Let me know if you have no idea how to query database and populate in dropdown list)

3) Without Ajax, you can use onchange of the state drop down list to populate Local govt by getting the selected item. (Without Ajax ur page will refresh but your problem will be solve.) The base practice is to use Ajax (though it's socially constructed) because most sites still use traditional method that refresh the entire page.


Let us know if you are a newbie in php meaning that you can't query database table and populate a combo or dropdown box for more assistance.




Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='".$lga[$i]."'>".$lga[$i]."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)

1 Like

Re: How Can I Code This In Php/html? by oluagness(m): 2:27am On Dec 11, 2013
Nekon J: First thing your table structure should be

State Table
CREATE TABLE State
(
name VARCHAR(30) PRIMARY KEY
);

CREATE TABLE LGA
(
LGAName VARCHAR(30),
state VARCHAR(30) REFERENCES State (name)
)

I expect you to know how to interact with database using php(Load or Query data).

You need Ajax just because you don't want your page to refresh but i will advice you get the logic of how to implement your problem.

1) Create form that have <select> or drop down list for state and local govt.
2) Populate the state dropdown list with what you have in your database (Let me know if you have no idea how to query database and populate in dropdown list)

3) Without Ajax, you can use onchange of the state drop down list to populate Local govt by getting the selected item. (Without Ajax ur page will refresh but your problem will be solve.) The base practice is to use Ajax (though it's socially constructed) because most sites still use traditional method that refresh the entire page.


Let us know if you are a newbie in php meaning that you can't query database table and populate a combo or dropdown box for more assistance.



great having you. I query db but combo box, list and drop down often give me issue.
Re: How Can I Code This In Php/html? by oluagness(m): 2:34am On Dec 11, 2013
robzyone:

Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='$lga->LGA'>".$lga->LGA."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)
i will be wright back, let me put it in practice. Please don't mind my ignorance
Re: How Can I Code This In Php/html? by oluagness(m): 2:34am On Dec 11, 2013
robzyone:

Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='$lga->LGA'>".$lga->LGA."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)
i will be wright back, let me put it in practice. Please don't mind my ignorance
Re: How Can I Code This In Php/html? by oluagness(m): 2:37am On Dec 11, 2013
robzyone:

Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='$lga->LGA'>".$lga->LGA."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)
i will be wright back, let me put it in practice. Please don't mind my ignorance
Re: How Can I Code This In Php/html? by oluagness(m): 2:37am On Dec 11, 2013
robzyone:

Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='$lga->LGA'>".$lga->LGA."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)
i will be wright back, let me put it in practice. Please don't mind my ignorance
Re: How Can I Code This In Php/html? by ire4me: 2:58am On Dec 11, 2013
@ op, I think you need to go and sleep and come back some other time. You are quoting and posting the same words for more than three times. lol grin grin grin.
Back to my own parole, I think i need to be spoon fed, lol. I am totally lost.
@robzyone and Nekon J, please use Lagos State (Ikeja & Ikoyi for LG) and Ogun State (Otta & Abeokuta for LG) in place of State. I am a slow learner that need practical examples. shocked
Re: How Can I Code This In Php/html? by ire4me: 3:01am On Dec 11, 2013
Back to bed and check back during the day sad
Re: How Can I Code This In Php/html? by oluagness(m): 2:01pm On Dec 11, 2013
ire4me: @ op, I think you need to go and sleep and come back some other time. You are quoting and posting the same words for more than three times. lol grin grin grin.
Back to my own parole, I think i need to be spoon fed, lol. I am totally lost.
@robzyone and Nekon J, please use Lagos State (Ikeja & Ikoyi for LG) and Ogun State (Otta & Abeokuta for LG) in place of State. I am a slow learner that need practical examples. shocked
you are on your own
Re: How Can I Code This In Php/html? by losprince(m): 10:49am On Dec 13, 2013
Re: How Can I Code This In Php/html? by talk2hb1(m): 7:06pm On Dec 14, 2013
You keep spoon feeding him code, without asking him what he has done?
What are the challenges is facing and how do you be of help?
Knowing is half the battle undecided
@OP what have you done?
What are the challenges you are encountering and how do we be of help?
Re: How Can I Code This In Php/html? by dyweb(m): 9:03pm On Dec 14, 2013
robzyone:

Lemme just continue from here. This should be on the page you want to display the states and lga
Your jquery should look like this

<script>
$(document).ready(function() {
$('#state').change(function(){
var state= $(this).val();
$("#lga"wink.load("ajax.php",{state:state, ajax: 'true'});
});
});
</script>


Am assuming you are using select <select></select>
This is how your select should look like


<select name="state" id="state">
{list of all states here is an example <option value="Lagos">Lagos</option> }
</select>

//leave the lga empty
<select name="lga" id="lga">
</select>


On the ajax.php file you should have this:

if(isset($_POST['state'])){
//am assuming you have a function which connects with the db to get the lgas for a random state
$lgas = get_lgas_from_state($_POST['state']);
$options = "";
if($lgas){
for($i = 0; $i< count($lgas); $i++){
$options .="<option value='".$lga[$i]."'>".$lga[$i]."</option>";
}
}
//if you want to have others in the option. Include the below code else skip
$options .="<option value='Others'>Others</option>";
echo $options;
}


This will change the LGA on the page anytime there is a change on the states.

I hope i have been able to explain myself well. Find attached a list of the countries in the world, states and LGAs in Nigeria. (I hope it attaches)

Delegation is the best for your change event. So based on your code it will be
$("#mainbodydiv').on("change", "#stateselect" function(e) {
e.preventDefault();
Rest of the code

});

This is also good if you are dynamically adding the state select form to your mainbodydiv on the page.

1 Like

Re: How Can I Code This In Php/html? by Nobody: 10:42pm On Dec 18, 2013
oluagness: i have basic knowledge of it. What should i do?

Basic knowledge of what!!!! @op like me, u are still a learner Oooo!!!. There is no such thing as auto generate in programming, u have to type all d states and local govt in it, unless u download them and paste them in your code, do u even know what a programming language is!!!

Well, I'm still a learner what do I know

(1) (Reply)

Does Interswitch Payment Gateway Work With Joomla? / Data Sources (odbc) Drivers Missing In Win 7 Ultimate / 13 Year Old Indian Boy Hired By Google At A Package Of 1.25 Million Dollar/year

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.