Page 1 of 1
insert into db question [solved]
Posted: Fri Mar 25, 2005 12:02 pm
by reverend_ink
Hi everyone, I am needing to finalise a bit of code and havent done this before and wondering how I would go about it. I have checked google but results coming up dont answer the question, so thought I would ask real people...
Thanks in advance...
Now onto the question.
I have a form where a user inputs a numeric value (i.e. 1,2,3 etc) and upon submission I want it to generate an insert a string into the database for each of the values entered (i.e. enter 2 and the result will INSERT jkdfij00 once and 2309029jjj for the second entry).
I hope I am making myself clear enough.
Thanks everyone!
Posted: Fri Mar 25, 2005 12:23 pm
by pthomas
So you're saying that if the user enters in the number 5 then you want to insert five strings into the DB?
I'm not sure if thats what you're going for or not.
Paul
Posted: Fri Mar 25, 2005 12:27 pm
by reverend_ink
pthomas wrote:So you're saying that if the user enters in the number 5 then you want to insert five strings into the DB?
I'm not sure if thats what you're going for or not.
Paul
Close.
The script needs to take a numeric posted variable (5) and then on submit insert the same number of times as the variable.
This will insert a random value into the db but has to post a random key the same number of times as the posted numeric variable.
Posted: Fri Mar 25, 2005 12:35 pm
by Pyrite
Just use a loop to call the same insert query that many times, each time dynamically putting something different in the insert query.
Posted: Fri Mar 25, 2005 12:45 pm
by reverend_ink
Pyrite wrote:Just use a loop to call the same insert query that many times, each time dynamically putting something different in the insert query.
thats what I am asking for. This is an area I have not done before.
Regards
Posted: Fri Mar 25, 2005 12:53 pm
by pthomas
try something like this:
Code: Select all
//Get the passed user value
$loop = $_POST['user_number'];
//Loop the specified number of times
for ($ctr = 0; $ctr < $loop; $ctr++) {
do something
do something else
}
For more info on php functions, look at
http://us4.php.net/manual/en/control-st ... oreach.php
Paul