/    Sign up×
Community /Pin to ProfileBookmark

Enter multiple rows into a database

I am creating a script that will allow employees to enter their billing codes online. I have several drop downs with the same codes and a text area next to each for the quantity. Foe example the employee may need to bill 1 x JC 415, 3 x JC452 and so on. These each need to go into a seperate row. i.e. jc415 – 1 into one row and then jc452 – 3 in another and so forth. Also if the employee does not enter data I need it not enter that. for example there are 15 drop downs. Maybe the employee uses 1 of the drop downs I do not need the other 14 to enter any data. I am attaching a photo of this. Any help would be appreciated.

[url]http://parkwoodtech.com/images/codes.jpg[/url]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@zimonyiNov 29.2010 — Can you please ask your question?

You can only ever INSERT one row at a time if you have the data yourself (and not selecting it from other tables).

So basically you would need to store your codes in an array and loop through that array and INSERT each item.

But I am not sure that is what you are asking for.

Archie
Copy linkTweet thisAlerts:
@NogDogNov 29.2010 — Actually, you can have multiple rows in one insert statement:
<i>
</i>INSERT INTO table (col1, col2, col3) VALUES
('foo', 'bar', 'fubar'),
('manny', 'moe', 'jack'),
('red', 'green', 'blue)

So what you can do is build up an array of value clauses, then implode() them with a comma.
[code=php]
$values = array();
foreach($something as $thing) {
$values[] = sprintf(
"('%s', '%s', '%s')",
mysql_real_escape_string($thing[0]),
mysql_real_escape_string($thing[1]),
mysql_real_escape_string($thing[2])
);
}
$sql = "INSERT INTO table_name (col1, col2, col3) VALUES " . implode(",", $values);
[/code]
×

Success!

Help @parkwoodtech spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...