suttercain Posted May 3, 2007 Share Posted May 3, 2007 Hi guys, Right now I am using this code: <?php if (isset($_GET['id'])) { $sql = "SELECT characters FROM comics WHERE comic_id = '" . mysql_real_escape_string($_GET['id']) . "'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); } } } if ($row['characters'] == !NULL) { $people = explode (", ", $row['characters']); echo "<b>CHARACTER(S):</b><br><font color='#263B5A'>" ; sort ($people); foreach ($people as $key=> $val) { $val_escaped = mysql_real_escape_string($val); $rez = mysql_query ("SELECT name, character_id FROM characters WHERE name = '$val_escaped'") or die(mysql_error()); while ($row = mysql_fetch_assoc($rez)){ echo "<a href='../view_characters.php?id={$row['character_id']}'>" . $val . "</a> "; } } ?> What this code does: I have a column in my MySQL table that contains characters that appear in a specific comic book. The characters a seperated by a comma. EXP: Superman, Lois Lane, Green Lantern, Perry White. This code echos the characters and allows the user to click on, let's say Superman, and view his profile. The problem I am having: Let's say I have Superman, Lois Lane, Green Lantern, Perry White in that cell. If I don't have a profile for Perry White, it won't echo his name in the character list. My Desired results: If there is no profile for a character, instead of not showing the name at all, is it possible to just have that character not "clickable"? So Superman, Lois Lane, Green Lantern would be links because they have a profile, but Perry White would be echoed, just not a link? Example Page: http://www.supermandatabase.com/comics/view_comics.php?id=4515 The character section is at the very bottom. Thank you for your advice and help. Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/ Share on other sites More sharing options...
thedarkwinter Posted May 3, 2007 Share Posted May 3, 2007 Can you do something like: <?php ...... while ($row = mysql_fetch_assoc($rez)) { if ($row['character_id'] == "") { echo $val; } else { echo "<a href='../view_characters.php?id={$row['character_id']}'>" . $val . "</a> "; } } ?? Cheers, tdw Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244413 Share on other sites More sharing options...
suttercain Posted May 3, 2007 Author Share Posted May 3, 2007 Hi Darkwinter, Thanks for the reply. Sadly that still only echoed the three characters who have profiles and not the ones without. Any other suggestions? Thanks again. SC Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244433 Share on other sites More sharing options...
thedarkwinter Posted May 3, 2007 Share Posted May 3, 2007 okay, sorry i didn't read properly... try <?php... $rez = mysql_query ("SELECT name, character_id FROM characters WHERE name = '$val_escaped'") or die(mysql_error()); if (mysql_num_rows($rez)==0) { echo $val; } else $row = mysql_fetch_assoc($rez)); echo "<a href='../view_characters.php?id={$row['character_id']}'>" . $val . "</a> "; } might work ?? Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244436 Share on other sites More sharing options...
suttercain Posted May 3, 2007 Author Share Posted May 3, 2007 That script caused it to echo nothing. Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244448 Share on other sites More sharing options...
thedarkwinter Posted May 3, 2007 Share Posted May 3, 2007 couple of errors in my swift typing try <?php... $rez = mysql_query ("SELECT name, character_id FROM characters WHERE name = '$val_escaped'") or die(mysql_error()); if (mysql_num_rows($rez)==0) { echo $val; } else { $row = mysql_fetch_assoc($rez); echo "<a href='../view_characters.php?id={$row['character_id']}'>" . $val . "</a> "; } that should give a least something Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244456 Share on other sites More sharing options...
suttercain Posted May 3, 2007 Author Share Posted May 3, 2007 NICE!!! I made just had to add two } } at the end and it worked!!! Thank you so much for your help!!!! SC Link to comment https://forums.phpfreaks.com/topic/49827-solved-an-array-from-the-database-creating-links-and-stuff/#findComment-244464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.