Error when displaying image inside a php <td>

Asked

Viewed 244 times

0

I’m creating a panel I make a calculation of the time a OS ta open and depending on the result shows in the table a colored ball... only it’s not working out,:

Parse error: syntax error, Unexpected 'src' (T_STRING), expecting ',' or ';' in C: xampp htdocs painelti ti.php on line 177

But I’d like you to look at my code as well, because he may also be in some kind of trouble.

<body>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
       <a class="navbar-brand" href="index.php">Tecnologia | </a>  
    </div>

    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
      <ul class="nav navbar-nav">
        <li class="active"><a href="index.php"> Home <span class="sr-only">(current)</span></a></li>
        <li ><a href="ti.php">TI</a></li>
        <li ><a href="eletrica.php">ELETRICA</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="http://192.168.0.20/bigwiki/index.php" ><span class="glyphicon glyphicon-globe" aria-hidden="true">BigWiki</a></li>
      </ul>
    </div>
  </div>
</nav>


<?php
$query_pesquisa = mysql_query(" SELECT 
    o.numero AS CHAMADO,
    p.problema AS PROBLEMA,
    o.descricao AS DESCRICAO,
    o.contato AS CONTATO,
    o.telefone AS TELEFONE,
    o.data_abertura AS DATA_ABERTURA,
    i.inst_nome AS UNIDADE,
    a.sistema AS AREA,
    l.local AS SETOR,
    u.nome AS TECNICO,
    ua.nome AS ABERTO_POR,
    s.status AS STATUS,
    sls.slas_tempo AS TEMPO_DE_SOLUCAO
FROM
    ocorrencias AS o
        LEFT JOIN
    sistemas AS a ON a.sis_id = o.sistema
        LEFT JOIN
    localizacao AS l ON l.loc_id = o.local
        LEFT JOIN
    instituicao AS i ON i.inst_cod = o.instituicao
        LEFT JOIN
    usuarios AS u ON u.user_id = o.operador
        LEFT JOIN
    usuarios AS ua ON ua.user_id = o.aberto_por
        LEFT JOIN
    `status` AS s ON s.stat_id = o.status
        LEFT JOIN
    status_categ AS stc ON stc.stc_cod = s.stat_cat
        LEFT JOIN
    problemas AS p ON p.prob_id = o.problema
        LEFT JOIN
    sla_solucao AS sls ON sls.slas_cod = p.prob_sla
        LEFT JOIN
    prioridades AS pr ON pr.prior_cod = l.loc_prior
        LEFT JOIN
    sla_solucao AS slr ON slr.slas_cod = pr.prior_sla
        LEFT JOIN
    script_solution AS sol ON sol.script_cod = o.oco_script_sol
        LEFT JOIN
    prior_atend AS prioridade_atendimento ON prioridade_atendimento.pr_cod = o.oco_prior
WHERE
        a.sistema = 'Ti'
        AND s.status = 'Em Atendimento'
        AND o.status IN (1 , 2,
        3,
        4,
        7,
        12,
        15,
        16,
        19,
        21,
        22,
        28,
        29,
        25,
        26,
        27,
        28,
        29,
        30,
        31)
ORDER BY numero DESC")or die(mysql_error());

    if (empty($query_pesquisa)) {
    echo "Nenhum registro encontrado.";
    }
    ?>
<table class='datatable table table-hover table-bordered table-responsiv'>
   <thead>
     <tr>
        <th>CHAMADO</th>
        <th>PROBLEMA</th>
        <th>DESCRICAO</th>
        <th>CONTATO</th>
        <th>TELEFONE</th>
        <th>DATA</th>
        <th>UNIDADE</th>
        <th>AREA</th>
        <th>SETOR</th>
        <th>TECNICO</th>
        <th>ABERTO</th>
        <th>STATUS</th>
        <th>SOLUCAO</th>
        <th>FAROL</th>
     </tr>
    </thead>
    <?php
       echo"<tbody>";       
     while ($row = mysql_fetch_array($query_pesquisa)) {

     $DATAATUAL = date(Y-m-d);
     $DATAABERTURA = $row['DATA_ABERTURA']; //tem que estar no mesmo formato do de cima. Ex: AAAA-MM-DD
     // Usa a função strtotime() e pega o timestamp das duas datas:
     $time_inicial = strtotime($DATAABERTURA);
     $time_final = strtotime($DATAATUAL);
     // Calcula a diferença de segundos entre as duas datas:
     $diferenca = $time_final - $time_inicial; // 19522800 segundos
     // Calcula a diferença de dias
      $dias = (int)floor( $diferenca / (60 * 24)); // 225 dias
     // Exibe uma mensagem de resultado:
     echo "A diferença entre as datas ".$DATAABERTURA." e ".$DATAATUAL." é de <strong>".$dias."</strong> dias";
     // ente o 60 e 24 use *
     echo" <tr>";
        echo"<td>".$row['CHAMADO']."</td>";
        echo"<td>".$row['PROBLEMA']."</td>";
        echo"<td>".$row['DESCRICAO']."</td>";
        echo"<td>".$row['CONTATO']."</td>";
        echo"<td>".$row['TELEFONE']."</td>";
        echo"<td>".$row['DATA_ABERTURA']."</td>";
        echo"<td>".$row['UNIDADE']."</td>";
        echo"<td>".$row['AREA']."</td>";
        echo"<td>".$row['SETOR']."</td>";
        echo"<td>".$row['TECNICO']."</td>";
        echo"<td>".$row['ABERTO_POR']."</td>";
        echo"<td>".$row['STATUS']."</td>";
        echo"<td>".$row['TEMPO_DE_SOLUCAO']."</td>";
         if($dias == 1) { 
        echo "<td>"<img src='img/verde.png'>"</td>" }
     elseif($dias == 2) { 
        echo "<td>"<img src='img/amarelo.png'>"</td>" }
     elseif($dias == 3) { 
        echo "<td>"<img src='img/vermelho.png'>"</td>" }
       else{ 
        echo "<td>"<img src='img/vazio.png'>"</td>" };
     echo" </tr>";

     }   
  echo"  </tbody>";
 echo" </table>";

?>
<script type="text/javascript"> 
        $(document).ready(function() {
            $('.datatable').dataTable({
                "sPaginationType": "bs_full"
            }); 
            $('.datatable').each(function(){
                var datatable = $(this);
                // SEARCH - Add the placeholder for Search and Turn this into in-line form control
                var search_input = datatable.closest('.dataTables_wrapper').find('div[id$=_filter] input');
                search_input.attr('placeholder', 'Search');
                search_input.addClass('form-control input-sm');
                // LENGTH - Inline-Form control
                var length_sel = datatable.closest('.dataTables_wrapper').find('div[id$=_length] select');
                length_sel.addClass('form-control input-sm');
            });
        });

        </script>    

</body>
</html>

Att,

Otácio Barbosa

  • 1

    "Eta dirty code. Gsus........." According to Diego, I must edit my answer. So I’ll be kind. Dear friend, I advise you to first.

1 answer

0


In the if($dias == 1) are left some double quotes in your code. Change the following snippet:

if($dias == 1) { 
        echo "<td><img src='img/verde.png'></td>"; 
     } elseif($dias == 2) { 
        echo "<td><img src='img/amarelo.png'></td>"; 
     } elseif($dias == 3) { 
        echo "<td><img src='img/vermelho.png'></td>";
     } else{ 
        echo "<td><img src='img/vazio.png'></td>";
     };

Note: I initially said there was need to escape the apostrophe, but this is not necessary between double quotes.

  • Hi Diego continues to show error: Parse error: syntax error, Unexpected 'src' (T_STRING), expecting ',' or ';' in C: xampp htdocs painelti ti.php on line 177

  • @Otaciobarbosa where line 177 in code?

  • echo "<td>"<img src='img/verde.png'>"</td>" }

  • @Otaciobarbosa Did you change the if and elseifs as I posted here? This comment code is wrong, leaving quotes there.

  • It was really wrong, now it passed, ?

  • @Otaciobarbosa good, there is a question completely different from the question. You have to put the path according to the hierarchy of folders of your site on the server. The php page cited in the question has to be inside the same folder that the img folder is in for the path, the way it is, work.

  • Not Diego, entedi, actually what is wrong and the calculation is not working. Can see something wrong in the calculation ?

  • @Otaciobarbosa the problem is that this is another doubt and it turns out that the comments deviate from the answer and the question asked. Regarding calculations with date, I don’t have much mastery, but I suggest you create another question about it, there is a great crowd in this here at Sopt that will help you, for sure! : D

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.