ok i will explain exactly what im trying to do , i will have a go anyways

i have a while loop then a foreach in side of it checking to see if the $id variable is in the array expel3

but its not working , anyone know why ?

while ($i < $rows) {
$name=mysql_result($result,$i,"name");
$subject=mysql_result($result,$i,"subject");
$type=mysql_result($result,$i,"type");
$id=mysql_result($result,$i,"id");

$sql="SELECT distinct username FROM online where roomid='$id'";
$ucount = mysql_query($sql);

$ucounted=mysql_numrows($ucount);

foreach ($expel3 as $eid) {

if ($eid == "$id"){
echo "something different";
$i++;
}
else {

echo "
<tr><td><img src='images/home.gif'> <a href=\"start.php?id=$id\">$name</a></td> <td> $subject</td> <td> $type</td> <td>$ucounted</td></tr>
";

$i++;
}
}
}

    you have $i++ in two different spots...might have something to do with it....try indenting your code and using the PHP formatting tags this site offers...it'll be easier to figure it out then maybe.

      well i did that so then the loop continues without continuing

        while ($i < $rows) {
        $name=mysql_result($result,$i,"name");
        $subject=mysql_result($result,$i,"subject");
        $type=mysql_result($result,$i,"type");
        $id=mysql_result($result,$i,"id");
        
        $sql="SELECT distinct username FROM online where roomid='$id'"; 
        $ucount = mysql_query($sql);
        
        
        $ucounted=mysql_numrows($ucount);
        
        foreach ($expel3 as $eid) {
        
        if ($eid == "$id"){
        echo "something different";
        $i++;
        }
        else {
        
        
        
        
        
        echo "
        <tr><td><img src='images/home.gif'> <a href=\"start.php?id=$id\">$name</a></td> <td> $subject</td> <td> $type</td> <td>$ucounted</td></tr> 
        ";
        
        $i++;
        }
        }
        }
        

        [/I]

          it's helpful when you indent your code. it helps folks see what code gets executed inside loops and IF statements you lazy sloth. what's it supposed to do anyway? what's not working?

          while ($i < $rows) {
            $name=mysql_result($result,$i,"name");
            $subject=mysql_result($result,$i,"subject");
            $type=mysql_result($result,$i,"type");
            $id=mysql_result($result,$i,"id");
          
            $sql="SELECT distinct username FROM online where roomid='$id'";
            $ucount = mysql_query($sql);
          
          
            $ucounted=mysql_numrows($ucount);
          
            foreach ($expel3 as $eid) {
              if ($eid == "$id"){
                echo "something different";
                $i++;
          
          } else {
          
            echo "\n<tr><td><img src='images/home.gif'> <a href=\"start.php?id=$id\">$name</a></td> <td> $subject</td> <td> $type</td> <td>$ucounted</td></tr>\n";
          
            $i++;
          } // if
            } // foreach
          }  // while 

            PS: That code is pretty poorly written. You might consider mysql_fetch_assoc() instead of mysql_result().

            Also, the $i++ happens every time your foreach loop gets executed regardless of what happens in the if statement.

            ALSO, the comparison $eid == "$id" is exactly the same without the quotes.

            you might want to try this before your foreach statement.
            reset($expel3)

              well what i want it to do is IF the $id is in the array of values from the database then print something different then continue the while loop

                yes , i understand its poorly written , its a quick job 🙂

                i added the " just incase that was causing a problem , your right its the same

                i did try reset

                  if $expel3 contains a list of ids for records that you DON'T want to print, you could do something like this

                  while($row = mysql_fetch_assoc($result) {
                    if (in_array($row['id'], $expel3)) {
                      echo 'RECORD EXCLUDED';
                    } else {
                      echo 'values:' . implode(',', $row);
                    }
                  }
                  

                    thank you very much for your time , i will continue with this tmr

                      Write a Reply...