Jump to content

Recommended Posts

Posted

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 :potofgold:

Posted (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 by btrfld
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...