Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
Los mensajes siempre se envían al primer amigo.

ingrese la descripción de la imagen aquí

Cuando hago clic en el 2.º, 3.º, 4.º... amigo, siempre es el 1.er amigo el que aparece en el modal, y cuando envío un mensaje a través de ese cuadro, siempre se envía al primer amigo. ¿Como puedó resolver esté problema?

 <div id="friends_list"> <?php $query2 = "SELECT id,username,photo_profil FROM accounts WHERE id in (SELECT id_res FROM frends WHERE (id_emtr='$id' or id_res='$id') and statu='1' UNION SELECT id_emtr FROM frends WHERE (id_emtr='$id' or id_res='$id') and statu='1')"; $query3 = mysqli_query($con,$query2); while ($row=mysqli_fetch_array($query3)) { $friend_name = $row['username']; $friend_photo = $row['photo_profil']; $friend_id = $row['id']; if ($friend_id != $id) { ?> <div id="a"> <div id="a_1"> <img <?php echo 'src="'.$friend_photo.'"'; ?>> <a href="#"><p><?php echo $friend_name; ?> </p> </a> </div> <div id="a_2"> <button id="delete" <?php echo'name="'.$friend_id.'"'; ?> >Delete</button> <a href="#openModal"><button class="message" id="message" >Message</button></a> <div id="openModal" class="modalDialog"> <div id="b_1"> <a href="#close" title="Close" class="close">x</a> <p>Message to : <?php echo $friend_name; ?></p> <form action="update_process.php" method="POST"> <div id="txt_area"><textarea name="msg_offline"> </textarea></div> <input type="hidden" name="idf" <?php echo'value="'.$friend_id.'"'; ?>> <div id="button_sub"><center><button type="submit" name="sub"><span id="send1">Send</span></button> </center> </div> </form> </div> </div> </div> </div> <?php } } ?> </div>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Todos los elementos que creas para diferentes amigos tienen la misma id .

Ejemplo simplificado:

 <div id="modal1">This is a modal</div> <div id="block1" onclick="showmodal('#modal1');">Friend 1</div> <div id="modal1">This is a modal</div> <div id="block1" onclick="showmodal('#modal1');">Friend 2</div>

Ahora hace clic en el segundo div y hace lo que se le dice, abre modal1 .

Lo que tendrás que hacer es crear un sufijo:

 $i = 0; while ($row=mysqli_fetch_array($query3)) { $i++; $idsuffix = '_idsuffix' . $i;

Para cada id , $idsuffix :

 <div id="openModal<?= $idsuffix ?>" class="modalDialog"> <div id="b_1<?= $idsuffix ?>">
over 4 years ago · Santiago Trujillo Report

0

Ok, antes que nada, siempre es bueno formatear tu código correctamente para que no cometas estos errores.

A su primera salida le falta un div de cierre

 <div class='container yep team-wrap'> <div class='row'> <div class='col-md-6'> <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'> </div> <div class='col-md-6'> <strong>$FullName<br>$JobTitle</strong> <br> <p>$Bio</p> <a href='mailto:$Email' class='btn btn-info'>Contact Me</a> </div> </div> </div> <!-- This was missing-->

por último, tuvo que cerrar su instrucción if para redondear rápidamente el siguiente código:

 //Start Gallery Row $output .= " <div class='row'> <div class='col-md-12'> <div id='gallery-slider' class='slider responsive'> "; } // CLOSED AT THE WRONG SPOT

Prueba lo siguiente:

 <?php $stmt = $db->prepare("my query"); $stmt->execute(); $result = $stmt->get_result(); $output = ""; $checker = []; while ($row = mysqli_fetch_assoc($result)) { $ID = $row['ID']; $FullName = $row['FullName']; $Email = $row['Email']; $JobTitle = $row['JobTitle']; $Bio = $row['Bio']; $Photo = $row['Photo']; $GalleryImage = explode(',', $row['GalleryImage']); if (isset($Photo) && ! empty($Photo)) { $ProfileImage = "$Photo"; } else { $ProfileImage= "avatar.jpg"; } if(!in_array($row['ID'], $checker)) { $output .= " <div class='container yep team-wrap'> <div class='row'> <div class='col-md-6'> <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'> </div> <div class='col-md-6'> <strong>$FullName<br>$JobTitle</strong> <br> <p>$Bio</p> <a href='mailto:$Email' class='btn btn-info'>Contact Me</a> </div> </div> </div> <!-- This was missing--> "; //End of info row $output .="<br /><br /><br />"; //Start Gallery Row $output .= " <div class='row'> <div class='col-md-12'> <div id='gallery-slider' class='slider responsive'> "; foreach ($GalleryImage as $img) { //Display this row as many times as needed by data in this row. $output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>"; } $output .= " </div> </div> </div> "; // End gallery row array_push( $checker, $row['ID']); } } $output .= "</div>"; echo $output; ?>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!