Jump to content

[SOLVED] If statement not working right


XpertWorlock

Recommended Posts

Hi, I have an if statement and it's not working right.  The "else" is always displayed.

 

while($row = mysql_fetch_array($result))
  {

$minusdate = (($dayday + $theday) - ($minusdayday + $minusday));
    
if ($minusdate == -1) {
  echo "<tr>";
  echo "<td>"Hello "</td>";
  echo "</tr>";}
  else 
  {
  echo "<tr>";
  echo "<td><a href=\"http://*********.org/wiki/Image:" . $row['img_name'] . "\" target=\"_blank\">" . $row['img_name'] . "</a></td>";
  echo "<td>" . $row['img_size'] . "</td>";
  echo "<td>" . $row['img_description'] . "</td>";
  echo "<td>" . $row['img_timestamp'] . "</td>";
  echo "<td>" . $minusdate . "</td>";
  echo "</tr>";
}
    
  
  
  }

 

 

the variable $minusdate is constantly being changed every time it loops (I have it in the html table working above)  So if one time $minusdate == -1, shouldn't it display nothing and loop to the next row??

 

I'm doing something wrong obviously.  No error's to help you guys with.

 

PHP 5.25

 

Link to comment
Share on other sites

This should help you troubleshoot:

 

while($row = mysql_fetch_array($result)) {

$minusdate = (($dayday + $theday) - ($minusdayday + $minusday));

// debug...
echo "Row with id " . $row['id'] . " has a minusdate of " . $minusdate . "<br />";
echo "Values were: ((" . $dayday . " + " . $theday . ") - (" . $minusdayday . " + " . $minusday . "))<br />";
echo str_repeat("-", 30) . "<br />";

if ($minusdate == -1) {
	echo '
		<tr>
			<td>Hello </td>
		</tr>';
} else {
	echo '
		<tr>
			<td>
				<a href=\"http://*********.org/wiki/Image:' . $row['img_name'] . '" target="_blank">' . $row['img_name'] . '</a>
			</td>
			<td>' . $row['img_size'] . '</td>
			<td>' . $row['img_description'] . '</td>
			<td>' . $row['img_timestamp'] . '</td>
			<td>' . $minusdate . '</td>
		</tr>';
}
}

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.