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
https://forums.phpfreaks.com/topic/111590-solved-if-statement-not-working-right/
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>';
}
}

Archived

This topic is now archived and is closed to further replies.

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