show image if exists

I have a strange need.
I am working with a MVC in php. I have two images I need to show or not show in an html file.

Now here is the deal I get a variable from the php file witch is passed to the html file.
In the html file it will look like this:
or {SRS}

Each can have either a 1 or a 0 as the value.

Now I don't want php to write the html code. Is there a way I can do this with javascript and or CSS to if {HD} is = 1 print:
<img src="{hdlogo.png" width="95" height="130" alt="" />

I aperciate your help.
Who is Participating?
You could simply have this CSS:

And in your template:

Your description is quite vague... Could you please try to make it more specific... Showing some HTML how it would look like...

And yes it is several ways of doing this in CSS or HTML... But what do you mean by "variable" being passed to HTML?
jbrashear72Author Commented:
OK so this is in a MVC meaning the PHP code and the HTML are separate.

So index.php <-- php code
and index.tpl.html is the html template used.

The index.php files is quering a data base to get data; ie

The .html file is parsed by the .php file. so The html file has a token {TITLE}
where {TITLE} is  the movie title will be passed.

in the case of two logos I have the database has a value of 1 or 0. 1 means show the logo. 0 means do not.

so {HD} has a value of 1 or 0. if it is one I want to show and image else don't.
I am hoping that I can do this in the html.
Other wise I would set {HD} to <img src="{hdlogo.png" width="95" height="130" alt="" /> but then I am breaking my rules and don't want the php code to create html.

Does that help?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

jbrashear72Author Commented:
PHP Code Example:
$stmt = $dbh->query("SELECT
					FROM movie
						LEFT JOIN movie_cover ON (movie.movie_id = movie_cover.movie_id AND movie_cover.cover_default='1')
					WHERE movie_status = 'enabled'
					ORDER BY movie.movie_rating DESC, movie.movie_votes DESC
					LIMIT 9");
while ($movie = $stmt->fetch(PDO::FETCH_ASSOC)) {

		$movie_actor = $dbh->query("SELECT	act.actor_name
									FROM movie_actor
									LEFT JOIN actor act on act.actor_id = movie_actor.actor_id
									WHERE movie_actor.movie_id = ".$dbh->quote($movie['movie_id']) . " LIMIT 6");
		$s_actors = array();
		while ($row_actors = $movie_actor->fetch(PDO::FETCH_OBJ))
			$s_actors[]= $row_actors->actor_name;
		$tpl->setVariable('MOVIE_ACTORS',implode(", ",$s_actors));

	$tpl->setVariable('MOVIE_SYNOPSIS', $movie['movie_synopsis']);

	$tpl->setVariable('MOVIE_ID', $movie['movie_id']);
	$tpl->setVariable('MOVIE_TITLE', $movie['movie_name']);

Open in new window

jbrashear72Author Commented:
HTML Template example:
<div id="content" class="row clearfix ">
  	<div id="movies" class="column inner popular grid_5 alpha">
		<h2 class="title"><span class="icon star-icon-blue"></span>Popular movies</h2>
		<div class="popularmovies clearfix">
		<!-- BEGIN popular_movie -->
		<div class="small-movie column movie-{MOVIE_ID}">
		<a href="/movie_details/movie/{MOVIE_ID}" class="info">
		<img src="{COVER_FILENAME}" width="95" height="130" alt="" />
		<div class="price"><tcb>{MOVIE_COST}</tcb></div>
		<span class="hd" <img src="/public/images/medium_hd.png" height="20px"></span>
		<div class="tooltip rounded">
		<h3><a href="/movie_details/movie/{MOVIE_ID}"><tcbmax>{MOVIE_TITLE}</tcbmax></a></h3>
		<img src="{COVER_FILENAME}" height="130" alt="" class="column alpha" />
		<div class="grid_3 column">
		<p class="no-indent">
		<!-- BEGIN actors --><b><tcb><big>Actors:</big></tcb></b> {MOVIE_ACTORS}<br/>
		<img src="/public/images/medium_hd.png" height="40px"/>
					<img src="/public/images/SRS_CS.png" height="46px"/><!-- END actors -->

Open in new window

jbrashear72Author Commented:
That is it. Yes thank you.
Hans LangerCommented:
This is other option, insert the complete IMG tag only if you variable HD = 1.
CSS solution will try to load the image anyway and it will get a LOST REQUEST.

On the template use:

And validate with PHP:
    $tpl->setVariable('MOVIE_HDLOGO', '<img class="display{HD}" src="{hdlogo.png" width="95" height="130" alt="" />');
jbrashear72Author Commented:
@GERENTE as I pu in my need above it cant produce the html code in the php.

@yogi4life  does the CSS have to be a block?

I have multiple images and they need to be aligned horizontally and now after the HD logo show it breaks the other images to the next line.
jbrashear72Author Commented:
I changed it from Block to inline. got it.
.display1 { display:inline }
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.