'Echo HTML tag problems with quotes

I am trying to put quotes in the php that handles the select tag. I need that the select tag displays the result of the query that is inside. How can I do this correctly?

<?php 
    $sql1 = mysql_query("SELECT * FROM `metlab`.`cutlog_junta` WHERE `finalizado` = 0")or die (mysql_error());
    $idtimeleft= 0;
    while($array = mysql_fetch_array($sql1, MYSQL_BOTH)){
        $idtimeleft++;                      
        $idprueba = $array[0];
        $id_log = $array["id_log"];
        $id_operador = $array["id_operador"];
        $started = $array["started"];
        $finished = $array["finished"];
        date_default_timezone_set("America/Mexico_City");
        $tiempo1 = new DateTime('now');
        $tiempo2 = new DateTime($finished);
        if ($tiempo1 < $tiempo2){
        $tiemporestante = date_diff($tiempo2,$tiempo1 );
        $timeleft = $tiemporestante->format("%h:%i:%s");
        }else{
        $timeleft = "00:00:00";
        }                       
        $sql = mysql_query("SELECT r.job AS JOB,p.heat_code AS HEAT_CODE,p.probeta AS PROBETA,p.id_line AS ID_LINE,p.id_box_pin AS ID_BOX_PIN,p.id_conexion AS ID_CONEXION
                            FROM metlab.prueba_junta p
                            INNER JOIN metlab.requerimientos_junta r ON p.id_job=r.id WHERE p.id='".$id_log."'")or die (mysql_error());
        $mhs = mysql_fetch_array($sql);                     
        echo (" <tr id='row". $idtimeleft ."'>
                    <td><input type='checkbox' name='record'></td>
                    <td>" . $id_log . "</td>
                    <td>" . $mhs['JOB'] . "</td>
                    <td>" . $mhs['ID_BOX_PIN'] . "</td>
                    <td>" . $mhs['ID_CONEXION'] . "</td>
                    <td>" . $mhs['HEAT_CODE'] . "</td>
                    <td>" . $mhs['PROBETA'] . "</td>
                    <td>" . $mhs['ID_LINE'] . "</td>
                    <td>" . $started . "</td>                           
                    <td><div id='idtimeleft" . $idtimeleft ."'>" . $timeleft . "</div></td>
                    <td><button type='button' class='btn btn-primary' data-toggle='modal' data-target='#cut_process'><i class='fa fa-cog fa-spin'></i>CUT</button>
                            <div id='cut_process' class='modal fade' role='dialog'>
                              <div class='modal-dialog'>
                                <div class='modal-content'>
                                  <div class='modal-header'>
                                    <button type='button'class='close' data-dismiss='modal'>&times;</button>
                                    <h4 class='modal-title'>CUT PROCESS</h4>
                                  </div>
                                  <div class='modal-body'>
                                    <input type='text' placeholder='INSERT COMMENT' class='form-control'><br>
                                        <label>Supervisor:</label>
                                        <select class='btn btn-primary'>
                                            <?php //////////////////////////////problem
                                            $query='SELECT nombre
                                            FROM metlab.supervisores';
                                            $result1=mysql_query($query);
                                            while($row1=mysql_fetch_array($result1)):;?>
                                            <option><?php echo $row1[0];?>
                                            </option>
                                            <?php endwhile;?>
                                        </select> /////////////////////////////end problem
                                    </div>
                                  <div class='modal-footer'>
                                    <button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
                                  
                                  </div>
                                </div>

                              </div>
                            </div>
                    </td>
                    <td>
                        <button type='button' class='btn btn-warning' data-toggle='modal' data-target='#milling_process'><i class='fa fa-cog fa-spin'></i>MILLING</button>
                            <div id='milling_process' class='modal fade' role='dialog'>
                              <div class='modal-dialog'>
                                <div class='modal-content'>
                                  <div class='modal-header'>
                                    <button type='button'class='close' data-dismiss='modal'>&times;</button>
                                    <h4 class='modal-title'>MILLING PROCESS</h4>
                                  </div>
                                  <div class='modal-body'>
                                    <input type='text' placeholder='INSERT COMMENT' class='form-control'>
                                  </div>
                                  <div class='modal-footer'>
                                    <button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
                                  
                                  </div>
                                </div>

                              </div>
                            </div>
                    </td>
                    <td>
                        <button type='button' class='btn btn-success' data-toggle='modal' data-target='#rectified_process'><i class='fa fa-cog fa-spin'></i>RECTIFIED</button>
                            <div id='rectified_process' class='modal fade' role='dialog'>
                              <div class='modal-dialog'>
                                <div class='modal-content'>
                                  <div class='modal-header'>
                                    <button type='button'class='close' data-dismiss='modal'>&times;</button>
                                    <h4 class='modal-title'>RECTIFIED PROCESS</h4>
                                  </div>
                                  <div class='modal-body'>
                                    <input type='text' placeholder='INSERT COMMENT' class='form-control'>
                                  </div>
                                  <div class='modal-footer'>
                                    <button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
                                  
                                  </div>
                                </div>

                              </div>
                            </div>
                    </td>
                    <td>
                         <button type='button' class='btn btn-danger' data-toggle='modal' data-target='#machined_process'><i class='fa fa-cog fa-spin'></i>MACHINED</button>
                            <div id='machined_process' class='modal fade' role='dialog'>
                              <div class='modal-dialog'>
                                <div class='modal-content'>
                                  <div class='modal-header'>
                                    <button type='button'class='close' data-dismiss='modal'>&times;</button>
                                    <h4 class='modal-title'>MACHINED PROCESS</h4>
                                  </div>
                                  <div class='modal-body'>
                                    <input type='text' placeholder='INSERT COMMENT' class='form-control'>
                                  </div>
                                  <div class='modal-footer'>
                                    <button type='button' class='btn btn-success' data-dismiss='modal'><i class='fa fa-paper-plane'></i>SEND COMMENT</button>
                                  
                                  </div>
                                </div>

                              </div>
                            </div>
                    </td>
                    <td>" . $finished . "</td>
                    <td>" .  $idprueba . "</td>
                </tr>");    
                                        
    }
?>


Solution 1:[1]

I think you should write directly HTML code inside the page avoiding PHP echo function.

In this example you use PHP short tag only when you need it:

<tr id="row<?=$idtimeleft?>">

And when you need to perform some action you just open PHP tag and write your code.

<select>
<?php
$query='SELECT nombre FROM metlab.supervisores';
$result1=mysql_query($query);
while($row1=mysql_fetch_array($result1)):
?>
<option><?=$row1[0]?></option>
<?php endwhile;?>
</select>    

You don't need semicolon after "while(...):"

Anyway you should read something about Twig to use template engine to write cleaner code. Bye!!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Riccardo Galeazzi