Jump to content

challenge for PHP begginer - please help :)


silberzin

Recommended Posts

Hej All

 

I am rather new to PHP and MySQL. I got task I do not know how to accomplish, therefore I hope you can help

 

I was asked to prepare few "chosing" fields which will be taking data from MySQL database with button add records.

 

Actually I have no clue how to start so I really hope you can help.

 

Here is what fields are needed:

 

Country

Town

School

 

from school new windog have to be open and class name should be listed.

 

In this sence, first we have to choose Country.

Country will be related for example when choosing USA, we will have list wit towns: NY, Chicago.....

town will be connected to school, unfortunatelly we have to remember that some schools are named:

school nr.1

school nr.2

that same names in different towns.

 

We also need buttom Add in that sence is easy to add records as countries, towns,schools, students

 

 

Please help to accomplish that task. I am new to PHP and MySQl, but I have to accomplish that task. If possible please describe code in ..."more simple way"...  so it make it easier to understand for bieginner :)

 

Please help.

 

Many thanks in advance.

 

BR

Michal

 

Link to comment
Share on other sites

first off do you have a standing database, with the collective of information that you need.. IE, all the Countries.. State & Providences of each country.. Town's, Cities, other that are within each state & providence of said country. Then do you have a list of schools and similar information?

 

Without that information already plugged into a database and stored into said database structure there is no hope of accomplishing what you want done. As there is no public database to my knowledge that contains all the information, and I know any that you could find containing all that information would likely cost a lot of money. You could go resource hunting and find all the information to plug into a database yourself too as pretty much we all have to do when working with custom applications.

 

However on the alternative side of things, if you already have a database, and standing information in it to use as part of a web application then we can help you better. But we need more information other than what you want done. We all, well some of us can do what you want done. But its no easy task without the existing data as there are thousands of countries, thousands of cities and towns, thousands of state/Providences, and thousands of schools. Example, Colleges only.. in the USA. There are 4400 or so, and thats not even a full list its missing a couple hundred. But that 4400 is spread across 50 states, across thousands of cities and towns.

 

I can take my list, and pull the data out of my database of these colleges that are in any given state, then fine tune the list further to whats in a particular region of the state. down to the town its in. Its a simple select query to the database where certain variables match other data in the database.

 

Again if you have the database already put together with relivant data we can better help you so long as we know how your data is stored in the database structure you have. 

Link to comment
Share on other sites

@thehippy I can agree with that.. However the striking issue at hand is still the school information. does the OP have a database of schools and locations of them to work with? Without that what they want to do is impossible.

 

Creating a pop up for all the countries, ok thats easy. Creating a list of States based off of choosen country ok, easy enough, listing towns based off the intial 2 constaints also easy enough so long as the data is consistent with one another wether its multiple tables or one single table of data being worked with. The schools on the other hand, thats the tough bit. It took me months to find the College data I mentioned earlier, and that comprised of me ending up composing a CSV in a word doc over time to then later dump in a DB. I found one database company that offered me the information but they wanted something like 1000+ dollars for it just the data and structure of 4400 or so colleges. Where the data was only College Name/Sub Name, City, State..

 

I guess what I am ultimately trying to prompt out of silberzin is what is the data and structure of said data they are working with currently, if any

 

 

Link to comment
Share on other sites

Hej

 

Thank you very much for your replay.

 

I must admit that task is rathe big to accomplish. However it seems it is possible to do it with your help.

 

This case do not reguire to have databases filled out, actually the data bases should be empty. That is good - I hope :)

There is something I was not thinking about in a first place, you are right first we should start with databases. First databases in MySql should be created.

 

 

Yesterday I installed MySql,PHP and Apache on my PC. I am totally new to this task. Can you help me, to create databases and then create code to have choosing field for countries, towns, schools, students (student should have: name and mark)?

There should be also button to add entries - but that one maybe can be next step.

 

 

Hope my simple description help a bit :)

 

Thank you very much for help.

 

BR

Michal

 

 

Link to comment
Share on other sites

All things considered I think your going to have to go the route of something like oDesk.com and hire someone to do this for you. Its not that its all seriously hard work or anything. But for someone fairly new to the concept of coding and database work this could be quite the under taking.

 

But bottom line is this is a help forum, not a freelance forum where you request a project to be done and we do it for. If you present a problem we can assist on then we will help you through the problem. But as of the moment you have nothing to work with as far as helping you goes, and all you seem to be saying is "show me the code that will make this idea work".

 

I've said to a point what your going to need for the basics to start this up, and you tell me no, its not needed. Which is the database. You can't generate a list of states for a country, and the towns for a state, and the schools for the towns or state from no data what so ever. There is no function.

 

echo generateListofSchools_by_state($state);

echo generateListofSchools_by_town($town, $state);

 

you have to build those functions to work with a database and various other coding techniques to pull such information. As there is much more to a web site/app other than what you see on the screen, under the hood of any decent site is a mass amount of coding that brings it all together. :)

 

AND I am sincerely sorry that I am being as rude as I am, I just want you to ultimately understand that this is a help forum, not a freelance forum.. You will have to sit for hours learning, and consuming information to start building what you want done. Unless you just go the freelance route. But if you don't want to spend money, don't think you need to, or just can't then you gotta learn to do it yourself, when you get stuck during learning we can help you cause you can present to us what your stuck on, right now theres nothing to show.

 

http://www.tizag.com is a good site to start learning the absolute basics of php/mysql and various other coding languages.

Link to comment
Share on other sites

Hej

 

You are of course right, I do not want others to do all the job for me as that is not the point. I would like to accomplish that task my self, but as a beginner I will need some "directions". I need to know all the solution as I will be maintaining it in the future. There is impossible to maintain solution with out greate knowledge about it, therefore I have to create it.

I am trying to create databases in MySql, but when data should be linked, coountry should be related to city. I do not know it there should some special configuration in databases.

Can you advice if I should create 5 different tables, and which of them should be master?

 

Thank you in advance for help.

 

BR

Rafal

Link to comment
Share on other sites

Well everything linking together is more so based off your coding, and logic you build into the coding. To put it best, code doesn't fail, humans fail.. Code does what its told to do by the humans. That in mind the easiest way to build a database is literally draw it out on paper first your going to have this data set looking through this data set for matching identifiers. Draw it out like a Mind map. One big circle in the middle, with 3 more circles out the outside. Main circle is your countries, the others are state, city, school. The logic behind what you want to present to the user is from what I persieve is they choose the country, from there they choose the state from there they choose the town from there they choose the school.. draw lines on your circles that match that concept, that train of thought and logic... there is your visual representation of what you want to do. Now, we code it to make it happen.

 

Now chances are you are not going to find a full database anywhere of All the countries, all the states, all the towns, and all the schools in one neat little package. On that same note, your not likely going to have it all in one master table. I know you can jump on Google and search for things like "php mySQL USA States" and in those results you will likely find a site that has a file to download that's literally copy and paste or just upload to your mysql server and let the server construct the table based off that file.. What you will likely end up with is a database table with 50 rows one state per row. Might even have the full state name and abbreviation for it. But it may not likely have the country its associated with. In this case since your wanting countries, your going to have to alter that table after you get it installed. Adding a new column to it, to associate a country code or name with it. Now with that new column you'll end up with 50 rows that have a blank column. where you would want to put USA or United States or whatever you want to identify the country with. Since you have a blank spot now I would go in an do a simple php based foreach style look. I would query the database table you now have for that name of that new column where the information in it is nothing, and just have it update the column within the foreach loop with your identifier for USA. Its not the most proper way to do that, but it would do the job.

 

Now that you have the states in line from this example I would then turn around and do the same thing with the countries, and same thing with the towns. Though I would start with the countries actually as that is your master link value in this case.

 

You get the countries, you get the table installed, if you find a good country data set your going to likely have something similar to the state concept above. hopefully with this scenario you have 3 columns when it comes to the countries. ID, Full Name, Abbr. The ID is going to be your best working bet in the overall run of things to use. When getting to the states table, but the Abbr. may be fine too. Now remember what I said with the states, add an extra column for an identifier for the country.

 

Well in your country table find the USA, find what ID it is, or what Abbr. it has we will use that in the extra column on the states table now. Now, how do you get this to work you may ask at this point. Well when you present the option to your users you are presenting them with a static landing page to pick there country from the lot. When they click on the link for their country, or post it through choices given you will want to use the ID or Abbr from the Country table as the variable that's being passed from country selection to listing of states from the country selection. example. states.php?ID=405 now with that 405 that's being passed in this example your going to have your state.php search the states table for the country identify of 405 in this example and then list all the matching rows. From there you apply the same logic to the cities.php and schools.php

 

Bottom line is you can always link any data together as long as you apply a logic to it.. and essentially since your again not likely to find a database with all the states, towns, countries, and schools in the same table together, and even if you did it would be a massive table, its likely best you have multiple tables anyway less load in the long run when doing your queries. Now also bare in mind the states table doesnt have to apply just to the USA, if can apply to all countries as well. As you will have your State/Providenece, its abbr. and its associated id from the countries table. again same applies to the cities and schools table.

 

Its going to be a lot of leg work, and there is not likely to be a quick fix solution that you copy paste and poof it works with only minor tweaking. But thats what goes on under the hood of any website.

Link to comment
Share on other sites

  • 4 weeks later...

Hej

 

You are of course right, I do not want others to do all the job for me as that is not the point. I would like to accomplish that task my self, but as a beginner I will need some "directions". I need to know all the solution as I will be maintaining it in the future. There is impossible to maintain solution with out greate knowledge about it, therefore I have to create it.

I am trying to create databases in MySql, but when data should be linked, coountry should be related to city. I do not know it there should some special configuration in databases.

Can you advice if I should create 5 different tables, and which of them should be master?

 

Thank you in advance for help.

 

BR

Rafal

 

http://php.net , http://php.net/mysql (mysql functions will be a big help)

Are you using phpMyAdmin or SSH to administer your DB's??

Link to comment
Share on other sites

Hej All

 

I am rather new to PHP and MySQL. I got task I do not know how to accomplish, therefore I hope you can help

 

I was asked to prepare few "chosing" fields which will be taking data from MySQL database with button add records.

 

Actually I have no clue how to start so I really hope you can help.

 

Here is what fields are needed:

 

Country

Town

School

 

from school new windog have to be open and class name should be listed.

 

In this sence, first we have to choose Country.

Country will be related for example when choosing USA, we will have list wit towns: NY, Chicago.....

town will be connected to school, unfortunatelly we have to remember that some schools are named:

school nr.1

school nr.2

that same names in different towns.

 

We also need buttom Add in that sence is easy to add records as countries, towns,schools, students

 

 

Please help to accomplish that task. I am new to PHP and MySQl, but I have to accomplish that task. If possible please describe code in ..."more simple way"...  so it make it easier to understand for bieginner :)

 

Please help.

 

Many thanks in advance.

 

BR

Michal

 

I will give you an example of how to do the country/ state/ school/ selection and we'll see if you can adapt it to your code.

 

You want to have a table called 'schools' or whatever name you prefer. In that table you should have:

 

1. ID (INT) [primary or key] auto_increment=on //this will be the id for every record created in this table

2. SCHOOL_ID(INT) - either auto_increment or pre defined

3. COUNTRY (VARCHAR(65))

4. STATE (VARCHAR(65))

5. SCHOOL (VARCHAR(max characther length))

 

Then with all of those columns populated it's easy to run a simple query to return the desired data, it's also easy to search the data a bunch of other ways as well.

 

Sample query:

<?php
    //Get States by Country
    $sql = "SELECT STATE FROM myTable WHERE COUNTRY = '".$_REQUEST['country']."'";
    $result = mysql_query($sql);
    if(!$result){die(mysql_error());}
    $rows = mysql_fetch_array($result);

    //then loop over the rows and echo them to the screen
    foreach($rows as $row){
        echo $row.'<br>';
    }
?>

 

That's a basic starting example. MySql will do all the searching for you, you just need to learn how to organize your tables effectively.

 

Good Luck.

 

E

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.