Php data disappears on page

Asked

Viewed 72 times

-1

I have a code in PHP and when viewing the page it cuts the text data.

echo '<div id="tabs-2">
<p><b>Ficha de Aptidão Médica:</b></p>

<p>Trabalhador (1) Validade:';
if ($exibe['MedicaValidade'] != '0000-00-00')
{
    if (strtotime($exibe['MedicaValidade']) < time()) 
    {
        echo '<span style="color:red">'.$exibe['MedicaValidade'].'</span>';
        echo 'Anexo :<a href="MostrarMedica.php?id='. $exibe['id'].'">&nbsp; Ver PDF</a>';
    } else {
        echo $exibe['MedicaValidade'];
        echo '<a href="MostrarMedica.php?id='.$exibe['id'].'">&nbsp; Ver PDF</a></p>';
    }
}

'<p>Trabalhador (2) Validade:';
if ($exibe['MedicaValidade2'] != '0000-00-00')
{
    if (strtotime($exibe['MedicaValidade2']) < time()) 
    {
        echo '<span style="color:red">'.$exibe['MedicaValidade2'].'</span>';
        echo '<a href="MostrarMedica2.php?id='. $exibe['id'].'">&nbsp; Ver PDF</a>';
    } else {
        echo $exibe['MedicaValidade2'];
        echo '<a href="MostrarMedica2.php?id='.$exibe['id'].'">&nbsp; Ver PDF</a></p>';
    }
}

inserir a descrição da imagem aqui

He shows up like this, disorganized.

I want to put:

Worker (1) Validity: 2014-30-05 Annex: SEE
Worker (2) Validity: 2014-30-05 Annex: SEE

And always show more if the date is different from 0000-00-00.

1 answer

1


The syntax of your file is all messed up. You forgot several echo and quotes without closing during the course of your code! The following code will work as desired:

<?php

echo '<div id="tabs-2">';
echo '<p><b>Ficha de Aptidão Médica:</b></p>';

if ($exibe['MedicaValidade'] != '0000-00-00') {
    echo '<p>Trabalhador (1) Validade:';
    if (strtotime($exibe['MedicaValidade']) < time()) {
        echo '<span style="color:red">' . $exibe['MedicaValidade'] . '</span>';
        echo 'Anexo :<a href="MostrarMedica.php?id=' . $exibe['id'] . '">&nbsp; Ver PDF</a>';
    } else {
        echo $exibe['MedicaValidade'];
        echo '<a href="MostrarMedica.php?id=' . $exibe['id'] . '">&nbsp; Ver PDF</a></p>';
    }
}

if ($exibe['MedicaValidade2'] != '0000-00-00') {
    echo '<p>Trabalhador (2) Validade:';
    if (strtotime($exibe['MedicaValidade2']) < time()) {
        echo '<span style="color:red">' . $exibe['MedicaValidade2'] . '</span>';
        echo '<a href="MostrarMedica2.php?id=' . $exibe['id'] . '">&nbsp; Ver PDF</a>';
    } else {
        echo $exibe['MedicaValidade2'];
        echo '<a href="MostrarMedica2.php?id=' . $exibe['id'] . '">&nbsp; Ver PDF</a></p>';
    }
}

However, to avoid repeating code, try to group the output of your database using repeating structures :

<div id="tabs-2">
<p><b>Ficha de Aptidão Médica:</b></p>

<?php
for ($i = 1; $i <= count($trabalhador); $i++) {
    if ($trabalhador[$i]['MedicaValidade'] != '0000-00-00') {
        echo '<p>Trabalhador ({$i]}) Validade:';
        if (strtotime($trabalhador[$i]['MedicaValidade']) < time()) {

            echo "<span style='color:red'>{$trabalhador[$i]['MedicaValidade']}</span>";
        } else {
            echo $trabalhador[$i]['MedicaValidade'];
        }
        echo "Anexo :<a href='MostrarMedica.php?id={$trabalhador[$i]['id']}'>&nbsp; Ver PDF</a>";
    }
}
?>

</div>

PS.: The above code will not work directly in your application, but notice the difference in organization and decrease in code repetition.

  • Thank you very much. But the one thing that didn’t work out which is when the validity is 0000-00-00 I don’t want it to show anything

  • Just move inside the if

  • This php is no longer used...because you don’t make a php like it should be .. with structure with functions and flames by ajax ;) and put what you want

Browser other questions tagged

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