简体   繁体   中英

List records in mysql using php but only one record appear in all?

<tbody>
<?php
   $query = mysql_query("select * from announce ") or die(mysql_error());
      while ($row = mysql_fetch_array($query)) {
       $date = $row['date'];
       $subject = $row['subject'];
       $ann = $row['ann'];
       $sender = $row['Sender'];
    $id = $row['id'];
         ?>
       <tr class="odd gradeX">
       <td><?php echo $row['date']; ?></td>
       <td><?php echo $row['subject']; ?></td>
       <td><?php echo $row['ann']; ?></td>
   <td><?php echo $row['Sender']; ?></td>
<td><a class='inline' href="#inline_content" id="<?php echo $row['id'] ?>"> Click Me</a></td>
       </tr>    

<div style='display:none'>
<div id='inline_content' style='padding:10px; background:#fff;'>
<p><strong><?php echo $row['subject']; ?></strong></p> <p align="right"><?php echo $row['date']; ?></p>
<p?><?php echo $row['ann']; ?>.</p>
<br><br>enter code here
<p>By: <?php echo $row['Sender']; ?> </p>  </div>

    <?php } ?>
     </tbody>

I'm popping up a jquery lightbox but the information in the lightbox is in the database when a button call the information it will pop up and when i click another button it has the same record from the first one but I'm calling a different one? Please Need Help! Thanks in advance!

The problem here seems to be the HTML generated by your PHP code. There would be zero to several divs generated by the PHP code where the id is the same: 'inline_content'. You could take a look at the source of the generated page to verify this. Thus when you try to show the content of 'inline_content', it shows the same one (either the first or last, not sure).

It could probably be solved by generating divs with different ids for each iteration of your while loop using an additional variable to count up in each iteration of the while loop of your PHP code. So your generated HTML will have target divs with different ids.

#inline-content-1
#inline-content-2
#inline-content-3
etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM