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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 ?? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.