Dropping an array into a MySQL table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Dropping an array into a MySQL table

Post by impulse() »

If I have an array with several items contained within, how would it be possible to drop the contents into a MySQL DB?

For example:

Code: Select all

$i[ID][NAME][AGE]
if that was my array and I had 3 columns in the MySQL table (ID, name, age), how would I insert everything in the array into the table.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Hmm... Maybe you meant to this?

Code: Select all

$i[ID]
$i[NAME]
$i[AGE]
ID, NAME and AGE are constants right? If they are not, wrap them with ' (single quote).
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Yeah, I had a dumb moment

:)
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Code: Select all

$sql = "INSERT
	INTO    `tbl_name` (id, name, age)
	VALUES  ('$i[ID]', '$i[NAME]', '$i[AGE]')";
Assuming ID, NAME and AGE are constants.
Post Reply