Good evening fellow insomniacs.
I am echoing a mysql database result which is stored in the database as such "Superman, Batman, Wonder Woman, etc"
I am using the explode to split the into an array using the comma as the delimiter.
Then I am trying to get it so if I click on Superman I am taken to the Superman profile page... Batman I go to the Batman profile page.
This is the code I am using:
if ($row['characters'] == !NULL) {
$people = explode (", ", $row['characters']);
echo "<b>CHARACTER(S):</b><br><font color='#263B5A'>" ;
sort ($people);
foreach ($people as $key=> $val) {
$rez = mysql_query ("SELECT name, character_id FROM characters");
while ($row = mysql_fetch_assoc($rez)){
echo "<a href='view_characters.php?id={$row['character_id']}'>" . $val . "</a><br>";
}
}
echo "</font><br><br>";
}
It echos out the following:
Batman <---Link to id 1 //Not Correct
Batman <---Link to id 2 // Correct
Batman <---Link to id 3 //Not Correct (No link to 3 should even appear)
Superman <---Link to id 1 // Correct
Superman <---Link to id 2 //Not Correct
Superman <---Link to id 3 //Not Correct (No link to 3 should even appear)
which is partually correct... but I want it to echo each only 1 time:
Batman
Superman (not three times each)
It feels like I am so close but I can't get it.
Any advice or suggestions?
Thanks