I have an array ($updateInputs) with 6 elements, 6 / 2 which each 3 belong to a single row in a database table. What I'm trying to do is put a query in a while loop so that every iteration, the index will be correctly placed for the next 3 elements. $i starts at 0 and gets + 1 every loop. I'm trying to do the following but it just crashes my website:
$tempMult = $i*3;
$updatedInputs = $_REQUEST['UPDATEDtoy'];
$query = "UPDATE TOY
SET TOYID='$updatedInputs[0 + $tempMult]', TOYName='$updatedInputs[1 + $tempMult]', TOYprice='$updatedInputs[2 + $tempMult]',
TOYmanufacturer='$updatedInputs[3 + $tempMult]'
WHERE TOYID='$exactID[$i]'";
Is there another way to go about this? I just need it so that the second loop, the index will start at 3->4->5. I assume it isn't possible to do operations inside queries? Any help is appreciated
EDIT (full version): this is what gets returned when I use
print_r($updatedInputs);
$tempMult = $i*6;
echo "$tempMult <br>";
I get :
Array ( [0] => foo1 [1] => moo1 ) Array ( [0] => foo1 [1] => foo2 [2] => foo3 [3] => foo4 [4] => foo5 [5] => foo6 [6] => moo1 [7] => moo2 [8] => moo3 [9] => moo4 [10] => moo5 [11] => moo6 ) 0
Array ( [0] => foo1 [1] => foo2 [2] => foo3 [3] => foo4 [4] => foo5 [5] => foo6 [6] => moo1 [7] => moo2 [8] => moo3 [9] => moo4 [10] => moo5 [11] => moo6 ) 6
as you can see, 0 and 6 is correct (in the case of 12 elements). It gets printed twice because there are 2 loops
EDIT2 (temporary NOOB solution):
I'm just going to use this as a temporary noobie solution until I see an answer:
$a = 0 + $i*6;
$b = 1 + $i*6;
$c = 2 + $i*6;
$d = 3 + $i*6;
$e = 4 + $i*6;
$f = 5 + $i*6;
$updatedInputs = $_REQUEST['UPDATEDtoy'];
$query = "UPDATE TOY
SET TOYID='$updatedInputs[$a]', TOYName='$updatedInputs[$b]' ...
WHERE TOYID='$exactID[$i]'";
$result = mysqli_query($link, $query);
0 + $tempMult
? what are you getting when you echo the $query and var_dump($updatedInputs ) ?