sorry about i m stucked in foreach loop

 $mysqli = new mysqli("localhost", "root", "root", "route");
 if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
$array  = $_POST['arrayorder'];====>array of id s sent from form
$jour=$_POST['day'];======>array of days  
if ($_POST['update'] == "update"){

     //in my foreach i want to set value for position value got from count 
     //ex: day has for example 10 or more 1 day of the month 
     //i can have 1 position 1
                  1  position 2 
                  1  position 3 and so 
                //  when day passes to  2 the position must be 1 and so 
                //  my problem the day is 2 but the position is conitnuation of the last day means 1

        foreach ($c as $idval=> $value) {

        $query = "UPDATE van SET week = '$count',position= '$count'  WHERE id = '$idval' and day='$value' ";
            if(mysqli_query($mysqli, $query)){
              echo "";  
               $count ++;

           } else {
               echo "ERROR: Could not able to execute $sql. " . mysqli_error($mysqli);}


    echo 'All saved! refresh the page to see the changes';

2 Years
Discussion Span
Last Post by asaidi

let me understand, you get two arrays from a form, for example:

$a = [1,2,3,4,5];
$b = [10,11,12,13,14];

Then you combine them to have $a as keys and $b as values and finally you loop them and use each pair as WHERE conditions in your update queries.

So what's the exact problem? Could you provide some example arrays and desired output? Also, how do you define the $count variable?


the first array is ids 1,2,3,4,,5,6,7,8.....
2nd array days..1'2'3'4'5'6,7....
for each 1 of day i can have 1 to 26(using count for looping) of 1st array and when the day 1 is finished
it passes to 2 and the same for 2 (count looping for 2 )and so for 3 ...until the end of the array
my problem the count does not go to 1 when the day 1 is finished and day 2 starts...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.