-1

So I have to call 25 articles from a mysql database and have the article title open a modal window containing the relevant article body. Is there a way to add a link in foreach that would dynamically reference the appropriate article?

for instance, when I click the title "Fish Sticks Taste Horrible" I should get the article talking about the awful tasting fish sticks in side the modal window.

I'm just starting with php and javascript so this is all really over my head. Any help would be very appreciated. this is what I have so far:

$results = $conn->query('SELECT title, byline, body, timestamp FROM PublishedDocs ORDER BY timestamp DESC LIMIT 25;');

<div class="list">
    <?php
    foreach ($results as $key) {
    echo '<a href="#" class="lightbox"><b>';print_r($key[title]); echo '</b></a>';
    echo '<p>';print_r($key[byline]); echo '</p>';
    echo '<p>';print_r($key[timestamp]); echo '</p>';
    echo '<p>';print_r($key[body]); echo '</p><br>';
    }
    ?>
</div>

<div class="backdrop"></div>
<div class="box"><div class="close">x close</div><b><?php print_r($key[title]);?></b><?php print_r($key[body]);?></div>
  • 1
    When you start to learn PHP where you get info what array keys need to write without quotes? – Narek Apr 12 '13 at 14:15
  • http://stackoverflow.com/questions/2405482/is-it-okay-to-use-arraykey-in-php – Narek Apr 12 '13 at 14:18
  • also, what is not working right now, specifically? Looking at your code the answer will be "a lot" but it is not our job to find that out. We expect more specific questions – Pankrates Apr 12 '13 at 14:40
  • @Pankrates You really got me there. What an idiot I must be. I should just give up and go back to coal mining. Thanks for the help. – Mike Gilbert Apr 12 '13 at 18:12

1 Answers1

0

Something like...

<?php

 foreach ($results as $key) {

   $link = "blabla".$key["title"];
   echo "<a href='$link' class='lightbox'>". $key['title'] . "</b></a>";
   ...

 }

 ?>

should work

Luigi Siri
  • 2,068
  • 2
  • 19
  • 27
fedorqui
  • 275,237
  • 103
  • 548
  • 598