Jump to content

Mutliple If Statements not working :(


valoukh

Recommended Posts

Hi all. I'm having trouble with the following If Statement, wonder if anyone can help. It's only displaying the first If, i.e. " if ($row['Row'] == "1" )". Not sure what I'm doing wrong. Thanks.

 

<?
while($row = mysql_fetch_array($result))
  {
  if ($row['Row'] == "1" )
  {
  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";
  echo "</table></td>";
  } else {
  }
}

echo "</tr><tr>";

while($row = mysql_fetch_array($result))
  {
  if ($row['Row'] == "2" )
  {
  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";
  echo "</table></td>";
    } else {
  }
}

echo "</tr><tr>";

while($row = mysql_fetch_array($result))
  {
  if ($row['Row'] == "3" )
  {
  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";
  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";
  echo "</table></td>";
    } else {
  }
}

mysql_close($dbh);
?>

Link to comment
Share on other sites

Great! That worked; all the brackets were confusing me a bit. I've got a different problem now - table related. I want the records to display on different rows, 1, 2 and 3. So let's say I've got three records for each row, I want to end up with a grid of 3x3. At the moment they're all in one column. Got any ideas? I'm having trouble spotting the problem!

 

Thanks so much for your help.

 

<?

while($row = mysql_fetch_array($result))

  {

  if ($row['Row'] == "1" )

  {

  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";

  echo "</table></td>";

  }

 

echo "</tr><tr>";

 

  if ($row['Row'] == "2" )

  {

  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";

  echo "</table></td>";

  }

 

echo "</tr><tr>";

 

  if ($row['Row'] == "3" )

  {

  echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";

  echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";

  echo "</table></td>";

  }

}

Link to comment
Share on other sites

I don't see any difference is the output for each if statement. You can combine the if statements into one.

<?php
while($row = mysql_fetch_array($result)) {
  if ($row['Row'] == "1" || $row['Row'] == 2 || $row['Row'] == 3) {
      echo "<td><table style='margin-left: 20; margin-right: 20;' width='100%' border='0' cellspacing='0' cellpadding='0'>";
      echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='title'><a href='../Photos/" . $row['Path'] . "_big.jpg' target='_blank'><img src='../Photos/" . $row['Path'] . "_sml.jpg' /></a></p></td></tr>";
      echo "<tr><td height='10' style='vertical-align: top' colspan='2'><p class='main'>" . $row['Caption'] . "</p></td></tr>";
      echo "</table></td>";
  } 
}
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.