Show corresponding message PHP

0

Good!

I'm doing a website at the university and it's the first time I use php, so I do not know much about the language and web development in general.

The problem I have is the following:

I have an array of objects called $ recibidos where I have saved all the messages that a user has received (each message is an object) and I show them in a table such that:

<tbody>
     <?php 
         for($i = 0; $i < count($recibidos); $i++) {
             echo '
                 <tr>
                     <td><a onclick="leer()">'.$recibidos[$i]->getAsunto().'</a></td>
                     <td>'.$recibidos[$i]->getEmisor().'</td>
                     <td>'.$recibidos[$i]->getFecha().'</td>
                 </tr>
             ';
         }
     ?>
</tbody>

The read () function only hides the table and shows the div to read the message (Everything is displayed on the same page).

This is the result:

So far so good, the problem is that I want that when I click on the subject field of the message I show you the corresponding message, but I do not know how to access it.

If I do something like this:

<div id="leer">
     <div>
         <label>De: </label> <?php echo $recibidos[$i]->getEmisor();?>
     </div>
 </div>

Obviously, it does not matter which message you click on because it is always going to show me the sender of the last message.

How can I do so by clicking on the first message read the fields of the first message? Do I have to create a separate variable or function, or is there some php function that allows me to do something like that?

    
asked by Pablovg 25.05.2017 в 13:35
source

1 answer

0

Well punctually that you do not do it with PHP, if not with javascript and css the message you can have it in hidden div for example

<div class="mensaje" id="identificador-unico-1"> xxxxxx</div>
<div class="mensaje" id="identificador-unico-2"> xxxxxx</div>

Regarding the link you should have something like for example

<a onclick="leer('identificador-unico-1')">

When the user clicks on the link, the read function selects the div and shows it, you can do it with the jQuery functions if you do not want to turn the subject around a lot.

the functions would be hiden and show is no more or you can look for others with a good animation.

link

    
answered by 25.05.2017 в 15:07