简体   繁体   English

列出使用php的mysql中的记录,但是总共只出现一条记录?

[英]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? 我正在弹出一个jQuery灯箱,但是当一个按钮调用将弹出的信息时,灯箱中的信息将在数据库中,并且当我单击另一个按钮时,它具有与第一个相同的记录,但是我调用了另一个一? Please Need Help! 请需要帮助! Thanks in advance! 提前致谢!

The problem here seems to be the HTML generated by your PHP code. 这里的问题似乎是您的PHP代码生成的HTML。 There would be zero to several divs generated by the PHP code where the id is the same: 'inline_content'. 由PHP代码生成的ID相同的零到几个div:“ 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). 因此,当您尝试显示“ inline_content”的内容时,它将显示相同的内容(不确定是第一个还是最后一个)。

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. 可以通过为while循环的每次迭代生成具有不同id的div来解决此问题,该div使用一个额外的变量在PHP代码的while循环的每次迭代中进行计数。 So your generated HTML will have target divs with different ids. 因此,您生成的HTML将具有具有不同ID的目标div。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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