Help with if/else in displaying data - (possibly foreach)
Hello all,
I've been trying to set something up, and I'm having difficulty getting it to work.
Lines 84-111 have become my biggest difficulty. I've got an if/else statement set up so that if one record has an image located on the localhost that image is pulled up. The way I have it now, this works great.
If I swap lines 93-96 with 102-105, and just tweek line 90, I can get it to work if the image is located on an alias and not the localhost.
The problem is that if I have it like it is now, I can't get both to work at the same time. So, I'm trying to get the if/else statement to apply to each record that is being pulled up. It seems like what it is doing now is choosing which part of the if/else statement it needs to use for the first record, and then applies that for all records.
Is there a way to have it coded like it is now for the if/else statement (because I want to be able to add multiple alias' and just check to see if the image is on the localhost or not); but have the image be displayed no matter if the image is located on the localhost or an alias?
The following is what I've got so far:
<?php
$search = $_GET['series'];
$query_begin=" SELECT * FROM movies WHERE movie_name_series = '$search' ";
$search_begin = mysql_query($query_begin) or die(mysql_error());
$row_begin = mysql_fetch_assoc($search_begin);
if($row_begin == 0){
?>
<script type="text/javascript"><!--
setTimeout('Redirect()',0000);
function Redirect()
{
location.href = 'index.php?content=noresult';
}
// --></script>
<?php
}
else
{
$query_display = "SELECT * from series WHERE series_id = '$search'";
$result_display = mysql_query($query_display);
$row_display = mysql_fetch_array($result_display, MYSQL_ASSOC);
$series_id = $row_diaplay['series_id'];
$series_name = $row_display['series_name'];
?>
<h2>All Movies in our Library categorized in the series <?php echo $series_name ?></h2>
<br />
<div style="float: left; width: auto">
Click on the name of the movie to edit the movie.
</div>
<br />
<hr size="1" noshade="noshade" />
<br />
<?php
$query="SELECT * FROM movies
INNER JOIN family_rating ON movies.movie_star_rating=family_rating.star_id
INNER JOIN alias ON movies.alias=alias.alias_id
INNER JOIN parent_alert ON movies.parent_alert=parent_alert.alert_id
INNER JOIN rating ON movies.movie_rating=rating.rating_id
WHERE movies.movie_name_series='$search'
ORDER BY movies.movie_name ASC";
$result= mysql_query($query)or die (mysql_error());
while($row=mysql_fetch_array($result)){
// Display the data
?>
<table width="200" style="margin: 20px">
<tr align="center">
<td valign="top">
<h1 style="font-size: 12px"><?php echo $row['movie_name']; ?></h1>
</td>
</tr>
<tr align="center">
<td valign="top" style="width: 100%; border-bottom: ridge #FFF; border-left: ridge #FFF; background: url(assets/images/transback.png) repeat; padding: 10px">
<a class="ToolText" onMouseOver="javascript:this.className='ToolTextHover'" onMouseOut="javascript:this.className='ToolText'">
<style media="screen" type="text/css">
#coverart {
display: block;
width: 110px;
height: 150px;
}
#coverart:hover {
background: url("assets/icons/play_movie.png") no-repeat 0 0;
background-size: 110px;
}
</style>
<p>
<form action="index.php?content=play_movie" method="post">
<input type="hidden" value="<?php echo $row['movie_id']; ?>" name="movie" />
<input type="hidden" value="<?php echo $row['warning'] ?>" name="warning" />
<?php
if ($row['alias_name']='localhost') {
?>
<input onmouseover='this.src="assets/icons/play_movie.png"'
onmouseout='this.src="movies/coverart/<?php echo $row['art']; ?>"'
type="image" src="movies/coverart/<?php echo $row['art']; ?>"
style="border: none" height="150" width="110" />
<?php
}else{
?>
<input onmouseover='this.src="assets/icons/play_movie.png"'
onmouseout='this.src="http://<?php echo $row['ip_address']; ?>/<?php echo $row['alias_name']; ?>/coverart/<?php echo $row['art']; ?>"'
type="image" src="http://<?php echo $row['ip_address']; ?>/<?php echo $row['alias_name']; ?>/coverart/<?php echo $row['art']; ?>"
style="border: none" height="150" width="110" />
<?php
}
?>
</form>
</p>
<span><h2 align="center"><?php echo $row['movie_name']; ?></h2>
<?php echo $row['rating_name']; ?>
<h4><?php echo $row['description']; ?></h4>
<?php
if($row['parent_alert']='1') {
?>
<p align"center"><img src="assets/icons/<?php echo $row['alert_file_name']; ?>"></p></span>
<?php
} else {
}
?>
</a>
<img src="assets/icons/s_<?php echo $row['star_file_name']; ?>" />
</td>
</tr>
</table>
<?
}
}
?>
I've looked through a number of tutorials and it's been indicated to use a for each loop. However, I can't seem to get this to work. Is there anything I can do to get this to work the way I am trying to? Is it a problem with my if/else or do I need a for each? If I need a for each, how do I do that?
Thanks.
