Jump to content

n00b help needed (in reference to drop down menus)


wafflestomper

Recommended Posts

Hi everyone.  I've been searching around on the site a bit and am quite impressed with the extensive knowledge.  I just started learning php recently, so my knowledge is rather limited (but I'm trying to learn).

 

I am trying to create a profile type page.  I've gotten a login and register page working.  I've gotten it so that if there is already information stored in a mysql db, it can be displayed on the website. 

 

My next issue/problem is trying to figure out how best to give the user the ability to see what is already stored in their profile, and change it if 1. They haven't put anything there yet, or 2. it's wrong information.

 

I need the following fields to be filled. 

First Name

Last Name

School

Grade

Teacher

 

I was thinking the first 2 would be relatively easy with an text input field.

The 3rd will eventually hold 5-15 schools, so I was thinking a drop down menu would work well.

The grade could be either a drop down or a text field.

The teacher is based on which school they pick.  I was thinking this could be a drop down as well since people get the spelling of their teacher's names wrong (esp. the younger ones) which could mess up the tracking of which student had which teacher (or vice versa). 

 

Do any of you have some thoughtful guidance as to how to go about doing this?  Any code that you would like to provide would be fine as well...

Well there is a lot of text. I think you have table with for example all schools from your city or whatewer you should provide combobox to users (pupils) so they have to make choice. Thatway you will not get errors with wrong spelling and simillar. Also it's much easier for pupils to choose combo rather than write name of school.

 

I'm not sure about your question. Well I'll try to help a little if I understood you well:

 

- make two tables in db:

1. tbl_pupils

id fname lname school_id ...

 

2. tbl_schools

id school_name

 

When you make html of page for combo you need to populate whole table. It's easy. Walk trought table and add school_name + id from tbl_schools to combo:

 

echo '<select name="cbo_schools">
  <option value="' .$row['id'] .'">'.$row['school_name'].'</option>
</select>

 

Of course you can use while or for to walk trought whole table.

 

When use submit form you will got results in $_POST array. Check what is value of $_POST['cbo_schools']. That's ID of pupil's school which is selected in combo.

 

Update your db with query so you save school's ID in table tbl_pupils (field: school_id).

 

For fetching data from db you can use JOIN method to query:

SELECT tbl_pupils.*, tbl_schools.school_name 
FROM tbl_pupils 
LEFT JOIN schools ON tbl_pupils.school_id = tbl_schools.id

 

Well I'm not sure if this could be usefull for you. I wish good luck to you.

 

;)

 

 

Also you can add table teachers: (tbl_teachers) and add school_id in that table so you can connect every teacher to it parent-school.

I figured I'd build a little bit more detail on the php side...

 

Filling in a text field...

 

<input type="text" value="<?php echo $firstName ?>" name="firstName" />

 

Filling a "drop down" select is just a loop...

 

<?php
     $userSchool = 'School2';
     $schools = array('School1', 'School2');

     echo '<select name="schools">';
     foreach($schools as $school)
     {
          $selected = '';
          if($school == $userSchool) // is the user's school this one?
          {
               $selected = ' selected="selected"'; // if so, select it
          }
          echo '<option value="' . $school . '"' . $selected . '>' . $school . '</option>';
     }
     echo '</select>';
?>

 

there are many other ways of doing what you want.

Thanks both of you.  If there is any other help, it would be greatly appreciated.  Please don't be afraid to dumb it down for me as I am a beginner.  I won't be offended... :)

 

Once I understand exactly what I am trying to do, I'll try to clarify more, but both suggestions were very helpful (especially focusing even more on the php).

if you create a school table and a teacher table thus

[pre]

school                  teacher

-----------            ----------

sch_id      -----+      teach_id

sch_name        |      teach_name

                +----  sch_id

[/pre]

 

Then the baaSelect link in my sig will help

 

Another way is to use AJAX method to generate the teacher dropdown when the school is selected. Again, the AJAX link in my sig will help

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.