0

everyone! I have a chart for the doctors' work generated by an sql consultation. In it, I have the days that the doctor does not work, and I am showing it in an HTML table. The problem I have is that I can't find a way that instead of showing the days that he doesn't work, it shows the other days that he does work. I have tried with foreach and array diff giving to compare an array with the days of the week by array_search, array_diff but I can't achieve it and if I achieve it I don't know how to show those days in the html table either. To get to the point, what I need is to "replace" those dayOffs with "working days" and show them in my html table So I tried to compare the vector variable with an array with weekdays and with array_diff and to get back the days that are not in the vector variable:

I appreciate your help and thank you in advance

Here's my array

Array
(
    [0] => Array
        (
            [day_off1] => tuesday
            [day_off2] => thursday
            [day_off3] => monday
            [duracion] => 30
            [horariostart] => 08:00
            [horarioend] => 12:00
            [id] => 1
            [medico_id] => 1
            [servicio_id] => 1
            [Apellido] => RODRIGUEZ
            [NomServicio] => CLINICA
        )

    [1] => Array
        (
            [day_off1] => monday
            [day_off2] => 
            [day_off3] => 
            [duracion] => 60
            [horariostart] => 10:00
            [horarioend] => 14:00
            [id] => 2
            [medico_id] => 2
            [servicio_id] => 1
            [Apellido] => GONZALEZ
            [NomServicio] => CLINICA
        )

    [2] => Array
        (
            [day_off1] => friday
            [day_off2] => 
            [day_off3] => wednesday
            [duracion] => 30
            [horariostart] => 09:00
            [horarioend] => 13:00
            [id] => 3
            [medico_id] => 3
            [servicio_id] => 3
            [Apellido] => HERNANDEZ
            [NomServicio] => UROLOGIA
        )

    [3] => Array
        (
            [day_off1] => tuesday
            [day_off2] => friday
            [day_off3] => 
            [duracion] => 30
            [horariostart] => 07:00
            [horarioend] => 15:00
            [id] => 4
            [medico_id] => 4
            [servicio_id] => 2
            [Apellido] => PEREZ
            [NomServicio] => ODONTOLOGIA
        )

)

and here's How I show this data into html table:

thead>
        <tr>
         <td>DOCTOR</td>
         <td>ESPECIALITY</td>
         <td>START TIME</td>
         <td>END TIME</td>
         <td>INTERVAL</td>
         <td>DAYS OFF</td>
         </tr>
       </thead>
     <tbody>

<?php 
 

$resultarray= array();

if (mysqli_num_rows($sql1) > 0 ) {
while ($row = mysqli_fetch_assoc($sql1)) {
 echo '<tr>';

$resultarray []= $row;

$vector = [];

$DayOff = array();
$DayOff = $row['DIAS'];

$vector[] = $DayOff;
 

 
  echo '<td>'.$row['Apellido'].'</td>';
  echo '<td>'.$row['NomServicio'].'</td>';
  echo '<td>'.$row['horariostart'].'</td>';
  echo '<td>'.$row['horarioend'].'</td>';
  echo '<td>'.$row['duracion'].'</td>';
  echo '<td>'.$row['DIAS'].'</td>';
 
  echo'</tr>';  
  $contador ++; 


}
}

?>

</table>
 </table>      
     </div>
    </div>
   </div>
  </div>
  
 </body>
</html>
<?php
}
?>
Juan Perez
  • 23
  • 6
  • So what is your exact desired output from your sample input? Do you include the weekends? Are you writing comma-delimited day names in the `DIAS` column? I feel like there is a very good chance that I will close this page with https://stackoverflow.com/q/51347766/2943403. Just compose the 2nd parameter of `array_diff()` to be the 3 day elements as a single, flat array (the keys won't even matter). Okay, I talked myself into closing. – mickmackusa Jun 25 '20 at 01:19
  • @mickmackusa comparing with array_diff() it easy use it but I don't know how to use it with EACH records in my table. I mean I need repleace those days with the array_diff result comparing with an array('monday', 'tuesday', 'wednesday' 'thursday', 'friday', 'saturday', 'sunday') Im using CONCAT_WS(' ', in my sql query – Juan Perez Jun 25 '20 at 01:50
  • Then of course you will need to `explode()` on the spaces to create an array of off days. This is what you feed to `array_diff()` as the second parameter. You have posted a lot of irrelevant data in your question. You only really needed to show your collection of off days as a variable, an array of the days of the week, then your desired output. – mickmackusa Jun 25 '20 at 02:14

0 Answers0