Jump to content

if statement..


sabo86

Recommended Posts

hello guys

here part of my code:

 for ($i=0; $i <$num_results; $i++){
$row = mysql_fetch_array($result);
echo '<table width="800"  border="0">';
if( $i = $i%2 )
{
   
echo '  <tr bgcolor="#EFEFEF">';}
else
{

echo '  <tr bgcolor="#C3C3C3">';
}
echo '<td width="68" align="left" valign="top"><div align="left"><a href="'.$row["Picture"].'" target="_blank"><img src="'.$row["PictureThumbnail"].'" border="0" /></a></td>';
echo " <td><strong> ".($i+1).".Model : </strong>";
echo htmlspecialchars(stripslashes($row["Model"]));
echo "<br><strong> Description: </strong>" ;
echo htmlspecialchars (stripslashes($row["Description"]));
echo "<br><strong> Category: </strong>";
echo htmlspecialchars (stripslashes($row["Category"]));
echo "<br></td></table>";




}

 

The results seems to be infinite loop of rows that doesn't end...

any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/124379-if-statement/
Share on other sites

This one may make it more clear

 

$num_results = mysql_num_rows($result);

  echo "<p><i>Number of records found: ".$num_results."</i></p>";


  $Model = $Description = $Category = $Image = null;
    for ($i=0; $i <$num_results; $i++){
$row = mysql_fetch_array($result);
echo '<table width="800"  border="0">';
if( $i = $i%2 )
{
   
echo '  <tr bgcolor="#EFEFEF">';}
else
{

echo '  <tr bgcolor="#C3C3C3">';
};
echo '<td width="68" align="left" valign="top"><div align="left"><a href="'.$row["Picture"].'" target="_blank"><img src="'.$row["PictureThumbnail"].'" border="0" /></a></td>';
echo " <td><strong> ".($i+1).".Model : </strong>";
echo htmlspecialchars(stripslashes($row["Model"]));
echo "<br><strong> Description: </strong>" ;
echo htmlspecialchars (stripslashes($row["Description"]));
echo "<br><strong> Category: </strong>";
echo htmlspecialchars (stripslashes($row["Category"]));
echo "<br></td></table>";




}

Link to comment
https://forums.phpfreaks.com/topic/124379-if-statement/#findComment-642344
Share on other sites

The while loop worked... but the results are as following:

 

1.Model : Executive Office Arco

Description: Executive offices wooden frames anthracite lacquered; worktops, doors and drawer-fronts.

Category: European Office Furniture

 

2.Model : MOD. SERIE 2000

Description: Work Station

Category: Local Office Furniture

 

1.Model : MOD.098

Description: Anthropornetric desk

Category: School and University Furniture

 

2.Model : Operative Seatings T

Description: I love this descript

Category: Seatings

 

 

In other words, the numerations are 1 & 2 only!!! how can this be solved?

here is the code again:

$i=0;
while ($row = mysql_fetch_array($result))
{
echo '<table width="800"  border="0">';
if( $i = $i%2 )
{
   
echo '  <tr bgcolor="#EFEFEF">';}
else
{

echo '  <tr bgcolor="#D3D3D3">';
};
echo '<td width="68" align="left" valign="top"><div align="left"><a href="'.$row["Picture"].'" target="_blank"><img src="'.$row["PictureThumbnail"].'" border="0" /></a></td>';
echo " <td><strong> ".($i+1).".Model : </strong>";
echo htmlspecialchars(stripslashes($row["Model"]));
echo "<br><strong> Description: </strong>" ;
echo htmlspecialchars (stripslashes($row["Description"]));
echo "<br><strong> Category: </strong>";
echo htmlspecialchars (stripslashes($row["Category"]));

echo "<br></td></table>";$i++;

}

 

Thanks much

Link to comment
https://forums.phpfreaks.com/topic/124379-if-statement/#findComment-642372
Share on other sites

This if statement

<?php
if( $i = $i%2 )
?>

is using the single "=" which is the assignment operator. You should be using the double "==" which is the comparison operator for "equals". What you're doing now is reassigning $i to be $i%2, causing the infinite loop.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/124379-if-statement/#findComment-642386
Share on other sites

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.