Swap Table by topic

Asked

Viewed 86 times

0

i have the data to be shown so currently.

echo "<table>"; 
echo  "<tr><td>Nome:</td>";
echo "<td>".$exibe["Nome"]."</td></tr>";

echo  "<tr><td>Morada:</td>"; echo "<td>";
if ($exibe['Morada']){ echo $exibe['Morada'];}else{echo 'N/D';} echo "</td></tr>";

echo "<tr><td>Tipo:</td>";echo"<td>";
if($exibe['Tipo']){ echo $exibe['Tipo'];}else{echo 'N/D';} echo "</td></tr>";

echo "<tr><td>Email:</td>"; echo "<td>";
if($exibe['Email']){ echo $exibe['Email'];}else{echo 'N/D';} echo "</td></tr>";

Currently the data are shown all on the same page in table form ie:

 id - 1
 Nome[1] - Jorge
 Morada[1] - Rua do Sol
 Email[1] - [email protected]

 id - 2
 Nome[2] - Pedro
 Morada[2] - Rua da agua
 Email[2] - [email protected]

I want to change this for each id to appear in a different folder or window. 'Cause I’m gonna have thousands of Ids and if I leave everything on the same page it’s too long

Brighter?

  • I don’t understand, this Id would be $exibe['Id']?

  • Each "Topic" would store the information of each ID that was inserted. Topico1 = Id1 Topico2 = Id2 ....

  • You don’t understand the question. Is it about the structure of HTML? About how to get the Id in php? You can edit the question to make it clearer?

  • Each table would be a topic?

  • Remember to choose the best answer. You ask a lot of questions and those who answer like to get feedback as well. Hug.

1 answer

2

I don’t get it, but I’ll try. I think he’s trying to list and associate the results with the ID. Let’s try.

<script type="text/javascript">
// função javascript que receberá id e redirecionará para página ver.php passando o id
function go(id) {
    window.location = 'ver.php?id=' + id;
}
<script>

<table>
<tr>
    <td>Id:</td>
    <td>Nome:</td>
    <td>Tipo:</td>
    <td>Morada:</td>
    <td>Email:</td>
</tr>

<?php
// Se você tiver um array com vários sub-arrays com a estrutura do seu $exibe
foreach ($resultados as $exibe)
{
    // Primeiro recebo as variaveis
    $id = $exibe["id"];
    $nome = $exibe["Nome"];

    // Uso do operador ternário para simplificar o if
    $morada = ($exibe['Morada']) ? $exibe['Morada'] : "N/D" ;
    $tipo = ($exibe['Tipo']) ? $exibe['Tipo'] : "N/D" ;
    $email = ($exibe['Email']) ? $exibe['Email'] : "N/D" ;

    // Quando clicar na linha ele vai jogar para a página correspondente
    // O css é só pra deixar com a mãozinha quando por o mouse em cima
    echo  "<tr onclick='go($id);' style='cursor: pointer;'>";
    echo  "<td>$id</td>";
    echo  "<td>$nome</td>";
    echo  "<td>$tipo</td>";
    echo  "<td>$morada</td>";
    echo  "<td>$email</td>";
    echo  "</tr>";
}
?>   
</table>


See more about: Ternary Operator

Browser other questions tagged

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