insert array problem

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
gesf
Moderator
Moderator
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Fri Apr 17, 2009 9:20 am

foreach is your answer! Read this manual page ...

Give this code a try so you have an idea on how it works.
Example 1:

Code: Select all

<?php

$array = array("one","Two","Three","Four","Whatever");
foreach($array as $v) { print $v . "<br />"; }

?>
Example 2:

Code: Select all

<?php

$array = array("value 1","value 2","value 3","value 4","value whatever");
$string = '';
foreach($array as $v) { $string .= "'" . $v . "',"; }
print "INSERT INTO table contents VALUES(" . substr($string, 0, -1) . ");";

?>
Hope it helps!
Post Reply