Skip to content
Advertisement

tag not being echoed from php to html

I’m trying to echo a hiperlink tag from php to html inside a row in a table. However in HTML I try to click on the row and it isn’t clickable. Dont know what could I be doing wrong, any help is appreciated. Thanks!

<table id= "pacientes">
      <tr>
          <th>ID</th>
          <th>Nombre</th>
          <th>ƚltima actualizaciĆ³n</th>
          <th>Telefono</th>
      </tr>
      <?php
          $conn = new mysqli($servername, $username, $password, $dbname);
          if ($conn->connect_error) {
              die("Connection failed: " . $conn->connect_error);
          } 
          $sql = "SELECT ID, Nombre, Telefono, UltAct FROM Paciente WHERE Medico = '$ID'";
          $result = $conn->query($sql);

          if($result-> num_rows > 0){
              while($row = $result-> fetch_assoc()) {
                  echo "<a href=javascript:OcultarTabla(); id=paciente><tr><td>" . $row["ID"] . "</td><td>" . $row["Nombre"] . "</td><td>" . $row["UltAct"] . "</td><td>" . $row["Telefono"] . "</td></tr></a>" ;
              }
              echo "</table>";
          }
          else {
              echo "No hay pacientes registrados";
          }
          $conn->close();
        ?>

I know that the id and the href should have double quotations, but if I add them it gives me a syntax error. This way the html page loads up but the row isn’t clickable. The javascript function is the following.

 function OcultarTabla() {
          if (document.getElementById('paciente').clicked) {
             document.getElementById('pacientes').style.display = 'none';
          }
          else 
             document.getElementById('ifYes3').style.display = 'block';
        } 

Advertisement

Answer

instead of using double quotes ” ” for href and id use single qoutes ‘ ‘

when your using ” ” to define your string you need to use the single qoutations so you dont break out the string

(believe that’s the right terms feel free to correct if not)

so you should have: (I believe I put the quotes in the right place)

 echo "<a href='javascript:OcultarTabla();' id='paciente'><tr><td>" . $row["ID"] . "</td><td>" . $row["Nombre"] . "</td><td>" . $row["UltAct"] . "</td><td>" . $row["Telefono"] . "</td></tr></a>" ;
Advertisement