Good day!

Faced such a problem: you need to display data in a table (on the screen) after they are written to mysql. Can this be done inside a for loop? If so, how? In this code I create 2 arrays, then I calculate, if this element is not in mysql, then I add it.

The table will consist of 2 columns, the first will be the day of the week, the second drop-down list with the day of the week parameter.

<?php ... $massivName = array ('mon','tue','wed','thu','fri','sat','sun', 'WorkBeginR','WorkBeginKR','WorkBeginDO','WorkBeginHO', 'WorkEndR','WorkEndKR','WorkEndDO','WorkEndHO','DinnerR', 'DinnerKR','DinnerHO','DinnerTimeR','DinnerTimeKR','DinnerTimeHO'); $massivArg = array ('r','r','r','ho','kr','do','v','9:00','9:00','9:00','9:00','16:00', '15:00','13:00','14:00','13:00','12:00','12:30','45','30','20'); $lengmass = count($massivName); for ($i=0; $i < $lengmass; $i++){ $sql = "SELECT * FROM setup2 WHERE info = '{$massivName[$i]}'"; $result = mysqli_query($db, $sql); if ( mysqli_num_rows($result) == 0) { $sql = mysqli_query($db, "INSERT setup2 (info, setup) VALUES ('{$massivName[$i]}','{$massivArg[$i]}');"); } } 
  • @NewPhpUser, To format the code, select it with the mouse and click on the {} button of the editor. - Opalosolo
  • need to implement output only added records? or all records in the table? - 2ray
  • output specific data from the entire table, for example, from 1 to 7 id. those that are added do not need to display. - Strannikoff

0