Connecting Tech Pros Worldwide Help | Site Map

Help with populating an html form having more than one attribute

fjm fjm is offline
Needs Regular Fix
 
Join Date: May 2007
Location: California
Posts: 348
#1: Jun 17 '07
Hello all,

I know it wouldn't be long before I was back. I have a dilemma and really have no idea where to look for an answer. I have two issues going on and I appoligize in advance if I'm wrong for putting them both into one single post.

My first question has to do with more of a design issue than anything else.

I have an html form that will be populated with data from a mysql database using php. My *insert* form has the basic name, address, phone number information. I am starting to wonder how my form will insert more than one phone number or even customer location.

Say a customer has 15 (Highly unlikley but for example sake) telephone numbers. My insert form needs to have a list of fields that will allow the person to enter those numbers. I'm looking for a clean design. Can someone give me any pointers as to how this should be done?

My tables are like this:

Expand|Select|Wrap|Line Numbers
  1. customer_table
  2. customer_ID
  3. customer_Name
  4.  
  5. customer_Location_table
  6. customer_Location_ID
  7. customer_ID
  8. address1
  9. address2
  10. city
  11. state
  12. zip
  13.  
  14. customer_Phone_table
  15. customer_phone_ID
  16. customer_Location_ID
  17. phone_Type
  18. area_Code
  19. phone_Number
  20.  
So if my insert form looks like this:
Expand|Select|Wrap|Line Numbers
  1. Customer Name
  2. Address1
  3. Address2
  4. City
  5. State
  6. Zip
  7. Phone Type
  8. Area Code
  9. Phone Number
  10.  
  11. [SUBMIT BUTTON]
  12.  
How would I go about adding a second or third phone number to the db?
The only way I can see to add another phone number would be to place an insert new button next to all of the fields that can have *many* of one thing such as customer location, phone number what have you but this design tenique does not strike me as clean.

I would ultimately like to have "one" submit button that will enter everything in one shot.

My second question has to do with SERIALIZABLE transactions. Is this hard to set up? Do I need to set up the entire db to use them? Again, just advice. Thanks Guys!

Frank
shoonya's Avatar
Familiar Sight
 
Join Date: May 2007
Location: india
Posts: 159
#2: Jun 17 '07

re: Help with populating an html form having more than one attribute


replying to your first query...
Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2. var counter=1 // present no of rows
  3. function add_row(){
  4. ---
  5. use pre defined addRow function here to add another row to the table.
  6. var inp=document.createElemet('INPUT')
  7. inp.id='input_text_field'+counter;
  8. //append the inp to newly added
  9. counter++
  10. --
  11. }
  12. </script>
  13. <table><tr><td><input type=text name=text_field_id0></td</tr></table> Telephone No <a href=javascript:add_row()>add another</a>
  14.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

assign the id's serially and put the whole thing in a form
On your php page
Expand|Select|Wrap|Line Numbers
  1. $i = 0;
  2. while ( isset ( $_POST["text_field_id".$i] ) ==1){
  3. --
  4. put your query here
  5. --
  6. $i++; 
  7. }
hope it's clean enough
you can also add remove option by deleting the rows in the table.
similarly implement this thing to all the fields that may have more than one values

for storing in db you can make a separate a table like telephone_no, contact_details else you can use array data type to store the information in a single table

shoonya
fjm fjm is offline
Needs Regular Fix
 
Join Date: May 2007
Location: California
Posts: 348
#3: Jun 19 '07

re: Help with populating an html form having more than one attribute


Shoonya,


Thank you for you response and advice. I know that Yahoo mail has something similar when uploading a file (attachment). I'm not sure how to implement that into the code though. I am thinking about it and I'm not sure that it could work because I have a second table that is used as a FK in the phone table and indicates its type. Like this:

Quote:
phone_Type_Table
phone_Type

phone_table
phone_ID
phone_Type
area_Code
phone_Number
Some complete sample data would look like this:
Expand|Select|Wrap|Line Numbers
  1. phone_ID     phone_Type     area_Code     phone_Number
  2. 1                 Home                213                 555-1212
  3. 2                 Work                 312                        555-5455
  4.  
In order for me to use the javascript code you provided, wouldn't I have to also have some sort of a drop down box for the phone type as well? I just don't know how to impliment this.

Also, I have a question about my php design. Please bear in mind that this is my first real stab at trying to get something working with php. I have about 20 or so php forms written in pure html to look exactly how I want. I will go and insert the code into the html when I am ready.

My question is that I have seen many php scripts and I have never seen so many php scripts for each page. In other words, I usually see an index.php and class scripts. In my design, I will have 20 seperate php scripts and no classes. Is this a sucky design? Is there I way I can modulerize this some how without it becoming too difficult? I don't know OOP but I suspect that what I am referring to is OOP. Yes?

Thanks for the help.
shoonya's Avatar
Familiar Sight
 
Join Date: May 2007
Location: india
Posts: 159
#4: Jun 19 '07

re: Help with populating an html form having more than one attribute


hey even I dont use/know OOP :D

now for your drop down which has to be generated from the phone_type relation
[PHP]<?php
$query="select phone_type from phone_no_type";
$result=pg_exec($query);
if(!$result){
echo "<select size=1>";
for($i=0; $i<pg_num_rows($result); $i++){
$data=pg_fetch_array($result);
echo "<option>$data[phone_type]</option>";
}
echo "</select>";
}
?>[/PHP]

I guess this is what you want.
In case I am wrong do write back

shoonya
fjm fjm is offline
Needs Regular Fix
 
Join Date: May 2007
Location: California
Posts: 348
#5: Jun 19 '07

re: Help with populating an html form having more than one attribute


Quote:

Originally Posted by shoonya

hey even I dont use/know OOP :D

now for your drop down which has to be generated from the phone_type relation
[PHP]<?php
$query="select phone_type from phone_no_type";
$result=pg_exec($query);
if(!$result){
echo "<select size=1>";
for($i=0; $i<pg_num_rows($result); $i++){
$data=pg_fetch_array($result);
echo "<option>$data[phone_type]</option>";
}
echo "</select>";
}
?>[/PHP]

I guess this is what you want.
In case I am wrong do write back

shoonya

The fact that you don't know OOP either makes me feel a whole lot better. :)

The code you provided will pull the data into a drop down box but can I incorporate that code into that nice little javascript code to dynamically appear when a new phone number is required?

I guess what I mean is that the js code will allow a new phone number but we also need the phone type to go with the new number for the parent table or the insert will fail.

Is there a way to bring up a new phone textbox field and phone type drop down box all in one click? Or maybe a better way of designing this all together?

Thanks Shoonya.
shoonya's Avatar
Familiar Sight
 
Join Date: May 2007
Location: india
Posts: 159
#6: Jun 20 '07

re: Help with populating an html form having more than one attribute


yeah ofcourse you can do it
either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
one alternate unorthodox method is make a javascript array like

content_array = new Array();
loop{
--
content_array[i]=<?php echo &tel_type; ?>
---}
now use this array to make a string like this

var arg='<select><option>'+content_array[0]+'</option><option>......'
and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

hope you will get it

shoonya
fjm fjm is offline
Needs Regular Fix
 
Join Date: May 2007
Location: California
Posts: 348
#7: Jun 20 '07

re: Help with populating an html form having more than one attribute


Quote:

Originally Posted by shoonya

yeah ofcourse you can do it
either use ajax to dynamically create the drop down each time user wants to enter a new telephone number
one alternate unorthodox method is make a javascript array like

content_array = new Array();
loop{
--
content_array[i]=<?php echo &tel_type; ?>
---}
now use this array to make a string like this

var arg='<select><option>'+content_array[0]+'</option><option>......'
and now when any user will click to enter new phone no then along with showing him a text box show this string beside it or in a new cell

hope you will get it

shoonya

I'm sorry Shoonya.. its like showing a Japanese person Chinese writing. I don't understand javascript at all.

Is there or are there any ajax snippits out there that you could turn me on to that I can just kind of plug in? Maybe I am asking for something that is not possible. I don't know but it doesn't hurt to ask. :)

Thanks again. Frank
shoonya's Avatar
Familiar Sight
 
Join Date: May 2007
Location: india
Posts: 159
#8: Jun 20 '07

re: Help with populating an html form having more than one attribute


no problem dude :)

I will suggest you to go through any javascript basic site (w3school is good and precise).
It will enhance your skill set and surely will be of great help
and yeah as fai as my knowledge is concerned ajax doesn't has a plug-in
it's an extension of javascript (very easy to use) used for fetching data from db without refreshing the whole page

shoonya
shoonya's Avatar
Familiar Sight
 
Join Date: May 2007
Location: india
Posts: 159
#9: Jun 20 '07

re: Help with populating an html form having more than one attribute


go through some basic javascript functions/methods like

Expand|Select|Wrap|Line Numbers
  1. document.getElementById()
  2. ...innerHTML
  3. ...style.display
  4.  
shoonya
Reply


Similar PHP bytes