call image through the answer id in the form

Asked

Viewed 472 times

1

I have a form, where each answer the result is stored in the database and presented in a table:

<td> <center> <?php echo date('d/m/Y H:i:s', strtotime($row["data"])); ?> </center> </td>
<td> <center> <?php echo $row["nome"];?></center> </td>
<td> <center> <?php echo $row["img"];?></center> </td>

how do I call a certain image by the answer given in the form?

Example: User answered yes in the form and in the table an image x appears

  • This depends a lot on how the database structure was made, if used BOLEAN (True and False) can use this parameter in the HTML generated dynamically by PHP: ;<img src="<?php echo $variavel_do_resultado_do_db_referente_a_pergunta; ?>.png" alt="<?php echo $variavel_do_resultado_do_db_referente_a_pergunta; ?>" /> But without knowing the code or structure of the DB no chance of writing a clearer example than this.

  • It would be a kind of quiz?

  • right, as if it were a quiz

  • I am not using BOLEAN, I am using the basic name structure: varchar, data:timestamp, etc

  • in the table: <td> <center> <?php echo date(’d/m/Y H:i:s', strtotime($Row["data"]); ? > </center> </td> <td> <center> <?php echo $Row["name"];? ></center> </td>

2 answers

1

I managed to make the call, follow the way:<?php if($row["nometabelaBD"] == 'SIM'){ echo "<img src=\"img.jpg\">";} just do an if there and solved the problem, but thank you all for the comments

0

For id is unviable, since each record has a id, if you have 200 records, hypothetically you would have to create 200 images for each and create more images for the ids vindouros, which makes it unviable. But by the content of the question, I believe that is not the intention (only the title supposes this).

What you can do is create an image for each response type and go up to the server:

  • yes.png and
  • png.

When pulling the database data, just check what kind of answer was given and load the respective image. It would be something like this:

<td> <center> <?php echo date('d/m/Y H:i:s', strtotime($row["data"])); ?> </center> </td>
<td> <center> <?php echo $row["nome"];?></center> </td>
<td> <center> <img src="<?php echo $resposta;?>.png" /></center> </td>

Where the variable $resposta shall have the value of "yes" or "not" coming from PHP according to the answer given, and that will complete the image name in HTML.

Browser other questions tagged

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