Mysql Form/display Question

liunx

Guest
Hopefully I can explain this well enough, but I run a movie/DVD review website and after a couple hundred DVD reviews, I've run across a slight problem. In MySQL, I have a entry within my dvdreviews DB with a column called "edition". Well, what my problem is I don't know how to handle the coding side on my dvd review page if that entry is blank.<br /><br />Right now I have:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />$titleinfo2 = @mysql_query("SELECT title, year, edition FROM dvd_reviews WHERE id='$id'");<br />if (!$titleinfo2) {<br />  exit('<p>Error retrieving information from database.<br />'.<br />      'Error: ' . mysql_error() . '</p>');<br />}<br /><br />while ($info2 = mysql_fetch_array($titleinfo2)) {<br />    $title = $info2['title'];<br />    $year = $info2['year'];<br />    $edition = $info2['edition'];<br />    echo "$title ($year) - $edition";<br />}<br />?><!--c2--></div><!--ec2--><br /><br />If $edition is empty, how do I handle that dash?<br /><br />Also, I have a DVD reviews archive page where I have the same kind of issue:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$titlelist = @mysql_query("SELECT name, dvd_reviews.id, year, rating_overall, title, list_title, edition FROM critic, dvd_reviews WHERE criticid=critic.id ORDER BY list_title ASC");<br /><br />while ($listing = mysql_fetch_array($titlelist)) {<br />    $id = $listing['id'];<br />    $title = $listing['title'];<br />    $edition = $listing['edition'];<br />    $year = $listing['year'];<br />    $name = $listing['name'];<br />    $rating = $listing['rating_overall'];<br /><br />    echo"<br />    <TR><br />       <TD CLASS='rindex-year'>$year</TD><br />       <TD CLASS='rindex-link'><a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/'reviews/DVD/read.php?id=$id'><b>$title</b></a> ($edition)</TD><br />       <TD CLASS='rindex-critic'>$name</TD><br />       <TD CLASS='rindex-rating'><img src=http://www.totalchoicehosting.com/forums/lofiversion/index.php/'images/star_ratings/$rating.gif' HEIGHT='25' ALT='$rating'></TD><br />    </TR>";<br />}<!--c2--></div><!--ec2--><br /><br />Here, the edition is in parenthesis and I obviously don't want it to look like: Movie Title (), <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":p" border="0" alt="tongue.gif" /><br /><br />Any help in this would be appreciated.<br /><br />Thanks <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Hi, MovieMan.<br /><br />For the first example, there are a couple of ways to do it:<br /><br />echo "$title ($year)" . ($edition)?"<b> - $edition</b>":"";<br />or<br />$display_edition = ($edition)?"<b> - $edition</b>":"";<br />echo "$title($year)$display_edition";<br /><br />The second method probably involves less code for your second example:<br /><br />$display_edition = ($edition)?"<b> ($edition)</b>":"";<br />echo"<br />. . .<br /><TD CLASS='rindex-link'><a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/'reviews/DVD/read.php?id=$id'><b>$title</b></a>$display_edition</TD><br />. . .";<br /><br />Hope that helps. If I've misunderstood the question, just keep asking.<br /><br />Edit:<br />I just realized that I pasted your BBCode tags into mt answer and they got seen as BOLD tags for this post. Sorry. I'll bet you get the point, though.<!--content-->
Thanks for your help Jim.<br /><br />This one worked for my review page:<br /><br />$display_edition = ($edition)?" - $edition":"";<br />echo "$title($year)$display_edition";<br /><br /><br />But when I tried the other for my review index page, all the editions were absent. Not sure why because that's the same code as the other code that worked. I also tried it with the dash instead of parantheses, but same result.<!--content-->
Nevermind, I made a dumb mistake <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":p" border="0" alt="tongue.gif" /> Everything works now.<br /><br />Thanks again for your help Jim <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Don't you hate when that happens?<br />I'm glad it worked out for you.<!--content-->
 
Top