TheMovieman Posted September 15, 2007 Posted September 15, 2007 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. Right now I have: ><?php $titleinfo2 = @mysql_query("SELECT title, year, edition FROM dvd_reviews WHERE id='$id'"); if (!$titleinfo2) { exit('<p>Error retrieving information from database.<br />'. 'Error: ' . mysql_error() . '</p>'); } while ($info2 = mysql_fetch_array($titleinfo2)) { $title = $info2['title']; $year = $info2['year']; $edition = $info2['edition']; echo "$title ($year)[b] - $edition[/b]"; } ?> If $edition is empty, how do I handle that dash? Also, I have a DVD reviews archive page where I have the same kind of issue: >$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"); while ($listing = mysql_fetch_array($titlelist)) { $id = $listing['id']; $title = $listing['title']; $edition = $listing['edition']; $year = $listing['year']; $name = $listing['name']; $rating = $listing['rating_overall']; echo" <TR> <TD CLASS='rindex-year'>$year</TD> <TD CLASS='rindex-link'><a href='reviews/DVD/read.php?id=$id'><b>$title</b></a>[b] ($edition)[/b]</TD> <TD CLASS='rindex-critic'>$name</TD> <TD CLASS='rindex-rating'><img src='images/star_ratings/$rating.gif' HEIGHT='25' ALT='$rating'></TD> </TR>"; } Here, the edition is in parenthesis and I obviously don't want it to look like: Movie Title (), Any help in this would be appreciated. Thanks Quote
btrfld Posted September 15, 2007 Posted September 15, 2007 (edited) Hi, MovieMan. For the first example, there are a couple of ways to do it: echo "$title ($year)" . ($edition)?" - $edition":""; or $display_edition = ($edition)?" - $edition":""; echo "$title($year)$display_edition"; The second method probably involves less code for your second example: $display_edition = ($edition)?" ($edition)":""; echo" . . . <TD CLASS='rindex-link'><a href='reviews/DVD/read.php?id=$id'><b>$title</b></a>$display_edition</TD> . . ."; Hope that helps. If I've misunderstood the question, just keep asking. Edit: 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. Edited September 15, 2007 by btrfld Quote
TheMovieman Posted September 15, 2007 Author Posted September 15, 2007 Thanks for your help Jim. This one worked for my review page: $display_edition = ($edition)?" - $edition":""; echo "$title($year)$display_edition"; 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. Quote
TheMovieman Posted September 16, 2007 Author Posted September 16, 2007 Nevermind, I made a dumb mistake Everything works now. Thanks again for your help Jim Quote
btrfld Posted September 17, 2007 Posted September 17, 2007 Don't you hate when that happens? I'm glad it worked out for you. Quote
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.