Hi
sorry about i m stucked in foreach loop

<?php 
 error_reporting(0);
 $mysqli = new mysqli("localhost", "root", "root", "route");
 if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
$array  = $_POST['arrayorder'];====>array of id s sent from form
$jour=$_POST['day'];======>array of days  
$c=array_combine($array,$jour);
print_r(array_values($c));
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);}



           }
          $count=1;


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



?>

Recommended Answers

All 2 Replies

Hi,
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?

Hi
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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.