Note that there are some explanatory texts on larger screens.

plurals
  1. POforeach loop and select statment
    text
    copied!<p>The foreach loop never displays the link but if I remove my SELECT statement the $key displays, which can be seen here: <a href="http://www.rotaryswing.com/swingviewer/videos.php" rel="nofollow">http://www.rotaryswing.com/swingviewer/videos.php</a></p> <p>I am trying to create the link dynamically based on the IDs which in my foreach loop below are identified as $key.</p> <p>Displaying all the information works fine. All the source code for this can be found here: <a href="http://pastebin.com/hkC4L9UQ" rel="nofollow">http://pastebin.com/hkC4L9UQ</a></p> <p>I understand this is not the way i should store data but my knowledge lacks in how to do this any other way.</p> <p>The IDs are inserted into the Db into an array using implode then comma separated. I then explode them like so:</p> <p>echoing the key by itself works fine as expected.</p> <pre><code>//convert video id array to single lines $pieces = explode(",", $video_ids); //iterate through video IDS in our DB foreach ($pieces as $key) { echo $key; $query4 ="SELECT id, video_name, link, phase FROM videos WHERE id=$key"; if ($stmt4 = $mysqli-&gt;prepare($query4)) { $stmt4-&gt;execute(); /* bind result variables */ $stmt4-&gt;bind_result($id, $vid_name, $vid_link, $phase); /* fetch values */ while ($stmt4-&gt;fetch()) { echo "&lt;a href='http://www.rotaryswing.com/golf-instruction/video /rst-index.php?cat=$phase&amp;subcat=Rotary%20Swing%20Tour&amp;video=$id&amp;id=$vid_link&amp;name=$vid_name' target=\"blank\"&gt;" .$vid_name. "&lt;/a&gt;&lt;br&gt;"; } } } </code></pre> <p>You will notice the video IDs in sets of three numbers on this page. Evrything else works fine.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload