Forum Moderators: coopster

Message Too Old, No Replies

Boggling Question

         

jay7981

3:52 am on May 23, 2009 (gmt 0)

10+ Year Member



OK I have a form and in this form i am using JavaScript to utilize DOM and create extra fields on demand,

example:
Names of people in Household:
[text field](id=name1)
{link to add new text field}

when link is clicked a second text field is created with id=2 and so on and so on each time link is clicked the id is added +1

now this form submits to mysql database, and i need a php script that will some how create a new field if its not already there to input the id=x so if i have a table

id (primary key auto increment)
fname
lname
phone
blah
blah
blah
name1

it will first check to see if row name2 exists and if it does then great add info, if not create the row and then insert the info.

is this even possible? and if so could someone help me here i have tried so many different ways my head is about to explode!

ayushchd

7:56 pm on May 23, 2009 (gmt 0)

10+ Year Member



Just spare a thought.

Wouldn't it be better to store all the names in one single row separated by a comma or some other symbol?

Later on, when extracting from database, use the explode function to get distinct names.

janharders

8:01 pm on May 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



use a second table.
just add a table people_in_household with (assuming you're using mysql)
id int auto_increment,
customer (or whatever you call your users) int,
firstname varchar(255),
lastname varchar(255),
primary key (id, customer)

and insert it there, while customer is the id of the general customer data set you insert into your customer table. that's much cleaner than to dynamically change your database layout.

jay7981

12:52 am on May 24, 2009 (gmt 0)

10+ Year Member



ok so trying the explode fuction (i havent used this in a while) .. Should work like this correct?

The input:


$query = "INSERT INTO `table`(`housemembers`)VALUES ("$name1,$name2,$name3,$name4")" ;

To display:


$houselist = "$rows['housemembers']";
$delimiter = ",";
$array = explode($delimiter, $houselist);
foreach ($array as $value) {
echo $value;
}

ayushchd

5:58 am on May 24, 2009 (gmt 0)

10+ Year Member



Yes. Should.