user9545614
user9545614

Reputation:

Create popup boxes for each row in mySQL

So I have the following code:

$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);

while($rows=mysql_fetch_array($result)){
  $links = $rows['links'];
  $linksArray = explode(',', $links);
  if ($links == ""){
    unset($linksArray);
  }
?>
//LINK TO ACTIVATE POPUP BOX
<a href="#popup1">
<div class="newsBox">
      <h2><?php echo $rows['title'] ?></h2>
      <h4>Posted @ <?php echo $rows['date'] ?></h4>
      <?php
      if (!empty($linksArray)){
        ?>
      <span><i>Links associated with this post:</i>
      <? } ?>
      <?php
      foreach($linksArray as $link) {
        ?><a href="<? echo $link ?>">Here</a></span>
        <?
    }
    ?>
    <div id="popup1" class="overlay">
    <div class="popup">
        <h2>Here i am</h2>
        <a class="close" href="#">&times;</a>
        <div class="content">
        <?php echo $rows['news'] ?>
        </div>
    </div>
</div>
  </div>
<br>
</a>
<?php
}
mysql_close();
?>

For each row identified by my query, it links it to a popup box. However all the rows being outputted activate the same popup box. My question is how to create my popup box such that each row being outputted is linked to different popup boxes, if that makes sense. Such as the first row, when linked opens a popup box with that row's info. The next row after, when linked opens a popup box with that row's info, and so on. (I guess maybe like a dynamic popup box?)

Upvotes: 1

Views: 178

Answers (1)

PHPology
PHPology

Reputation: 1017

Add a counter in your loop and where you have your <a href="#popup1"> and <div id="popup1" class="overlay"> add in the counter variable like <a href="#popup<?php echo $x ?>"> and <div id="popup<?php echo $x ?>" class="overlay">

This would make your popup id unique.

Upvotes: 0

Related Questions