If i have the following:
$a = array();
and then want to use its elements in an update query i have been recommended to do as follows:
foreach($a as $value) {
$update = mysql_query("UPDATE tb SET username = '$value'");
}
However what do i do if i have many arrays and want to use the one element of each in the update?
Say…
$a = array();
$b = array();
$c = array();
$update = mysql_query("UPDATE tb SET username = 'element of a', image = 'element of b', address = 'element of c'...");
How would i use the foreach to achieve this. I am aware i could do:
$d = array($a, $b, $c)
But if this is any help forward i don’t know.
Thanks in advance for shedding any light on the problem…
Use a
forloop.Example:
$i is the counter, and you just loop through however many elements are in one array (You stated they all correspond to eachother), then pull out the same element number from each array.