Jump to content

foreach troubles


gibigbig

Recommended Posts

I have 5 arrays incoming via $_POST

$arrays1, $arrays2, $arrays3, $arrays4, $arrays5

and i want to know if this is possible:

foreach ($arrays1 as $arr1 && $arrays2 as $arr2 && $arrays3 as $arr3 && $arrays4 as $arr4 && $arrays5 as $arr5){

//execute mysql queries

}

if this is not possible, can you direct me to a method that will work?

 

PS, the number of records in each array is the same for all and is stored in $numberlinks

Link to comment
https://forums.phpfreaks.com/topic/205326-foreach-troubles/
Share on other sites

found a solution:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<form action="testing.php" method="post">
<input name="var[]" />
<input name="var[]" />
<input name="var[]" />
<br/>
<input name="v2[]" />
<input name="v2[]" />
<input name="v2[]" />
<input type="submit" />
</form>
<body>
<?php
$vars = $_POST['var'];
$v2= $_POST['v2'];
$numberlinks = 3;

$queries = array(); 
for($i=0; $i<$numberlinks; $i++) 
{ 
    $queries[] = "INSERT INTO anime (var1, var2) VALUES (" . $vars[$i] . "','" . $v2[$i] . ")"; 
} 

foreach ($queries as $query){
echo $query .'<br/>';
}

?>
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/205326-foreach-troubles/#findComment-1074634
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.