Work with all the fields returned by a PHP, JQUERY, MYSQL table

1

Good, I have a problem that is that I need to manipulate all the records that exist in a table, that is, I am creating an inbox, with inbox and the tables and the backend part are fine, it returns all the messages that they wrote to me, since all the messages they write to me are worth the redundancy, they are stored in the table and if they are for my registered user they are returned to me by the table, and in turn I show them on the screen the problem, in that as the messages come from different users for example, I need to access each of them, this is how to do it later, passing parameters, the problem is that the table the data that I returned can only manipulate a field! that is, it is like a bug that I can only touch the first record and the others are dead with no events, nothing and the idea is to work them all to see which user sends me a message, attach my code here

<?php
                            require_once 'wp-admin/history.php';
                            $data_message = new  history();
             $inbox = $data_message->inbox($_SESSION["id"],$_SESSION["nick"]);
                            if($inbox!=0){
                                $inbox_message = TRUE;
                            }else{
                                $inbox_message = FALSE;
                            }
                            if($inbox_message){                                
                                foreach($inbox as $key):
                        ?>
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="media">
                                    <a class="pull-left" href="#">
                                        <img class="media-object img-circle"                                          src="http://lorempixel.com/30/30/people/1/" alt="">
                                    </a>
                                    <div id="data_imbox" class="media-body">
                                        <h4 class="media-heading">Jane Smith
                               <span class="small  pullright">12:23PM</span>
                                        </h4>
      <p>Hi, I wanted to make sure you got the latest product report. Did Roddy get it to you?</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <hr>                                              
                           <?php endforeach;} ?>
                    </div>
                    </div>
                    <div class="portlet-footer">
                        <script>
                        jQuery("#data_imbox").click(function(){
                           alert("hello word"); // PARA testear, solo funciona con el primer registro que devuelve la tabla, es decir si la tabla hay 7 registros el primero que me devuelve es el que puedo manipular los otros 6 solo aparecen en mi div, pero como muertos, el DOM no lo he modificado con php para mostrar los mensajes de distintos usuarios
                        });
                        </script>
                    </div>

It should be noted that also try to do everything with pure php, and follow the same problem, events, everything you assign is given to the first record the others are as dead, only appear because the table returns

    
asked by Carlos Estarita 20.02.2017 в 21:45
source

1 answer

2

Good morning,

Given your code:

jQuery("#data_imbox").click(function(){
    alert("hello word");
});

Clearly it will only work with a single element, since the listener is giving it to the ID Element #data_imbox , but it turns out that all your elements have the same identifier and just the grace of the ID is that there can not be another element with the same ID.

My recommendation is that you give the listener the class attribute leaving it this way.

jQuery(".media-body").click(function(){
    alert("hello word");
});

I hope this example can serve you. Greetings.

    
answered by 20.02.2017 / 22:04
source