am developing a web application and I need some help.
I have in my database(MySQL) tables for village linked to the sub county table. Sub county linked to the county table and the county table linked to the District table.
I need to design a web form in dreamweaver using PHP for capturing people's details i.e Name,Date of Birth, Village, Sub county,County and District. But since I'll already have the District,County,Sub county and village in my DB, I need to create a drop down for village which after selection should populate automatically the Sub county,county and district text fields.
You can advise on the best way I could do this.
Cheers.
A simple query is in order? Just use an ajax request to send the selected country to a script, the script should return either XML data to fill the select box with or send the dom select box.
i'd go for the
<select onchange="ajaxGetWhatYouNeedByValue(this.value, 'populate some #id');"><option.....
as i understood your question, you need something like => when you select a village it should return all related data associated with the village. Therefore i suggest you using ajax for background loading needed data.
Related
its my first post here and im a bit worried about if it fits this forum.
Im making a project about a music library online, you signup in the website and you can add songs to your own list, something similar to spotify maybe. But i have some doubts about inserting the songs in the database because i dont want to have a popular song 30 times in the database, one idea i had is to only allow to insert songs in the database to an "admin" and people can see that admin song's list and add from there to their list and if the song you want is not in the list contact the admin but that seems tiring for the user. I guess another good option is that the form to add a song to your list shows you a select where you see existings album/songs and if you cant find it there then you create it in the database, but i need to think more into how to perform that idea.
The database is created with mysql, im pretty sure i will use pdo
database design
Finally i think is a better idea to connect library table with song instead of album so people can have couple songs instead of the whole album and im going to manage the inserts from the website with selects on the form so the user doesnt create already existing content, sorry for the post to that people downvoted it
The other idea you mentioned is a good option.
Say you have three dropdowns one of Artist, second of Album and third of songs. Here you can list all the Artists in the database in the first dropdown. On selecting an artist, the albums related to the artist selected can be populated in the second dropdown. On selecting an album from this dropdown can populate all the songs in that album in the third dropdown. If the user feels that the song he wishes to add is not available in the third dropdown, he can click a button saying 'Suggest an Addition'. Clicking this button, a popup will appear which will have a dropdown of Artists available in the database, and another dropdown of all the albums. Against this selection, he can add a song.
Also, I would suggest that every newly added song be subject to admin approval. This will prevent the duplicate entries of songs. For this, you can have a flag in the songs table which will be set based on admin approving the newly added song.
example:
Select Artist (dropdown 1)
Select Album (dropdown 2)
Select Song (dropdown 3)
Suggest an Addition (button)
So, I have a database for a mock phone site that has been built to the spec. My database has a table called phones, a table called operatingsystem and a table called manufacturer. I need to create a form to enter a new phone into the database. The problems I have run into are:
I need to basically get the form to add a new record to the phones table. However, the phones table pulls data from other tables as well. An example of this is how I have the operating systems (iOS, Android, BlackBerry and Windows Phone) stored separately in the operatingsystem table and each have an ID assigned (1, 2, 3 and 4) as well as having the manufacturers being stored in a manufacturer table (HTC, Samsung, Apple etc.) each with an auto increment ID. I'm not sure how I'd design the form so that the user can either add a new phone to the database simply by using the form or can add a new manufacturer/OS to the database if needed. I've got to do it assuming that the user adding the phones/editing existing ones hasn't got access to the database so obviously they don't know that manufacturer ID 1 is Apple, 2 Samsung etc.
I basically need to use a combination of a HTML form and accompanying PHP page so that phones can be added, edited or deleted altogether from the database. What would I do in terms of form design and what PHP would I need to use to be able to add/edit/delete data from multiple tables?
Sorry for the long-winded post but any help would be appreciated and if any more details are needed, please do not hesitate to ask. Thank you.
For selecting the manufacturer and operating system, the <select> element is the obvious choice. It creates a drop-down with selectable options, with a potential separation between the value passed and what the user sees.
So, if you had this:
<select name="manufacturer">
<option value="1">Apple</option>
<option value="2">HTC</option>
<option value="3">Samsung</option>
</select>
then the user would see Apple, HTC and Samsung as options. If they selected Samsung, then what would actually be submitted as that parameter's value is 3 (which would correspond to the id in your table).
For a simple/quick solution, #Anthony Grist's answer would do it. But, if you are aiming to build an automatized system that can 'live' on it's own, you'd need to build a <select> from PHP with the options that already exists and allow the user to add stuffs inside this <select> through a different CRUD. The problem with this is that users would be allowed to insert iOS, iOS 5, iOS 6, iOSasdf, etc; as they wish because you wouldn't be able to block it this much. If this is the case that you'd like to go, I'd suggest you to create a table to which you would use to feed the <select> in which table you'd have the operation_system and the table_name. If a new OS is being added, you'd use PHP to create a new table for this OS and then add it's name to the said table. When users select a OS in the select option, you'd pick that table and insert the record to it.
I have 2 Drop Down menus, both of which get their values from my database.
The 2 drop downs are - Town & County.
Obviously, only certain Towns relate to certain counties.
In order to capture this, they are stored within the database as such:
Leeds, Morley
Leeds, Chapel Town
London, Essex etc..
I need to force the user to choose the County first (which I have done by disable/enable). How ever, on selection of County, I need to refresh the 2nd drop down box with the related 'Town' values from the database.
The current code for 'Getting the town' is as such:
echo "<option value='0' >Choose a Town</option>";
$town_se=$_SESSION['town'];
if(isset($county_se)){
$locat=mysql_query("SELECT DISTINCT town_name FROM locations WHERE county_name='$county_se'");
}else{
$locat=mysql_query("SELECT DISTINCT town_name FROM locations ");
}
while($row=mysql_fetch_assoc($locat)){
$town=$row['town_name'];
echo "<option value='$town' >$town</option>";
}
Of course, this doesn't work! Is there a simpler way to replicate the results from the first drop down?
Many thanks in advance.
I'm having a hard time decoding what is going on in your example code. But just to make sure that we are on the same page... PHP is server-side and HTML is client-side. The two cannot interact without something in-between, like a new page-request, javascript or AJAX.
If the data you are presenting is reasonable in size, I would probably just recommend putting all that data in the HTML from the start, but hiding it. That is, create one dropdown for the towns in every county, but hide them all until the user selects a county. (Requires a bit of JavaScript)
Another common solution is to simply submit (and refresh) the page when the user selects a county, thus, you generate a new page with the town dropdown populated with towns for that county. (Requires a bit of JavaScript)
If you want to go really high-tech you could use AJAX and dynamically load the data into the second dropdown when the user selects a county. Although this requires that you have a pretty good understanding of PHP and JS.
I have a two part question with no code to show, but i hope you can help:
Essentially, i have a website which lets businesses create a profile for themselves (original table schema here).
Now within the site I want a form with three select lists in it: the first select list is for business catagory/tag - I have managed to create a query which will return entries from my main business registration table by using a Toxi solution.
However i also want a second select list with countries or regions, and a third select list with states/counties which will load automatically BASED on the selection from the Country select list.
Then naturally, on submitting the form, i want to return the results to the visitor.
So, apart from wondering how to achieve this much in PHP/MySQL, i have a more fundamental question about whether to set up the countries/states 'tagging' or 'catagories' field as another Toxi solution, or if there's a better way to do it. For instance, should i/can i just create seperate tables to populate the select lists with states/counties based on country selection, and have the actual country and state fields that a business selects on registration, stored within my main business table, and just match the strings when the user hits submit, in order to reduce queries to MySql and improve speed?
As always, your advice and help is greatly appreciated.
Thanks
Dan
Think about the "full name" of a state (or whatever political division is one level narrower than "country"). In the Americas, here are some "full names" of states.
California, US
Connecticut, US
Ontario, CA
Sonora, MX
Lara, VE
Base your lists on a two-column table of the full names of states.
ISO country codes
The critical point is that your selection lists shouldn't allow values like "Alabama, MX" or "Sonora, US".
I'm using html SELECT to make 3 drop-down menus. One for a list of countries, one for regions and one for cities.
They all have different tables in the database and they are linked to each other with foreign keys.
I want to force the user to first select a country while the other two menus are locked. When he has selected a country he will be able to select a region, and then a city. How do I do this?
Which part are you specifically having problems with?
1) Populate the countries list when the user loads the page, other 2 menus are disabled. (SELECT * FROM Countries;)
2) When the user selects a country, send an AJAX request to the server containing the country name. (SELECT * FROM Regions WHERE id = country_id;)
3) When you receive the AJAX response, populate the regions list and enable it.
4) Repeat steps 2 and 3 for the city name.
You've got several possibilities.
You could write a single select that retrieves all the country-region-city combinations at one time, and use the rows to create Javascript objects representing this data at load time. Then create a Javascript method that updates the dependent rows when a new country or region is selected.
You could write 3 select statements, 1 for countries, 1 for regions for a given country, and 1 for cities for a given region. The countries select would run at page load time, and the other queries could be performed using an Ajax request when country and region are selected.
Try this premade script and start accepting answers.., people might be more willing to help.