Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Help with if/else in displaying data - (possibly foreach)

Explorer ,
Jul 07, 2011 Jul 07, 2011

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.

TOPICS
Server side applications
760
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 08, 2011 Jul 08, 2011

9thReg wrote:

I've got a page that pulls up some records from a database, where I've got an if / else statement as part of the section where it displays the data.

                                    <?php 
          if ($row['alias_name']='localhost') {
         ?>

Thanks. That's much clearer, and it makes the error stand out immediately. You're going to kick yourself when you realize what it is.

Your condition in the if clause is assigning the value 'localhost' to $row['alias_name'] instead of co

...
Translate
LEGEND ,
Jul 08, 2011 Jul 08, 2011

9thReg wrote:

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?

Perhaps if you explained more clearly what it is you're trying to do, someone could help you. You refer to line numbers without indicating what code is on those lines, and you talk about tweaking a particular line, but don't say how you tweak it.

Everything might be clear in your mind, but I've read your description and looked at your code several times, and I've no idea what you're asking. Sorry.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2011 Jul 08, 2011

Thank you for your reply.  I apologize for not being as clear as I needed to be, so I'll try and explain better.

I've got a page that pulls up some records from a database, where I've got an if / else statement as part of the section where it displays the data.

                                    <?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
          }
          ?>


When the records are pulled, it seems like only the first part of the if / else statement is being applied to every record that is being pulled. The problem is if I've got records like the following:

Record one - (file on the host computer)

needs to be displayed from the condition

src="movies/coverart/<?php echo $row['art']; ?>"

Record two - (file on networked external hard drive)

needs to be displayed from the condition

src="http://<?php echo $row['ip_address']; ?>/<?php echo $row['alias_name']; ?>/coverart/<?php echo $row['art']; ?>

The way it's coded now, only record one will display the image (record two will not display the image).  If I swap the order of the conditions, only record two will display the image (record one will not display the image).

How do I get both record one and record two to display the image when both appear on the same page from a single search query?

If I still did not explain it well enough, please let me know and I will try and do better.  Again, thank you for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2011 Jul 08, 2011

9thReg wrote:

I've got a page that pulls up some records from a database, where I've got an if / else statement as part of the section where it displays the data.

                                    <?php 
          if ($row['alias_name']='localhost') {
         ?>

Thanks. That's much clearer, and it makes the error stand out immediately. You're going to kick yourself when you realize what it is.

Your condition in the if clause is assigning the value 'localhost' to $row['alias_name'] instead of comparing the two values. You need to use two equals signs:

<?php

if ($row['alias_name'] == 'localhost') {

?>

I haven't checked the rest of your code, but fixing the condition should sort out the main problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 08, 2011 Jul 08, 2011
LATEST

Thank you so much.  It's working now, and yes, I am kicking myself right now.  Thanks again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines