This loop does not show images from the database and show only one record .. where is the problem And how can i make the id changes with loop This loop to show per line two records but how the show every time a different record, such as the latest news and log appear according to the latest news added to the database?

 <table  class=" table" align="center">
<tr>
<?php
$conn=mysql_connect("localhost","root","1");
    mysql_select_db("society",$conn);
   $query="SELECT * FROM news ORDER BY id asc ";
   $result=mysql_query($query) or die(mysql_error());
   $max = 2;
   $num = 0;  
    while((($rows=mysql_fetch_row($result))>$num    )){
        $num++;

?>

 <td class="NewsListTD">
       <?php $m = new myclass();
             echo $m->gettitle(id); ?>
       <?php $m = new myclass();
             echo $m->getcontent(id); 

           echo" <img src='images/$row[pic]' width='60' height='60' />";?>

</td>

<?php

   if ($num == $max){   
    echo "</tr>";       

    $num = 0;   
    }   
}    
?>   


</tr>   
</table>    

From what i understood OOP is not com[patible with MySQL. You will need to use MySQLi or PDO wrapper.

Your increment is in the wrong place, this should be after doing X and looping, for example:

$i=1;
while($i<=5){
  echo "The number is " . $i . "<br>";
  $i++; #<-- increment at the end
}

You also have to many () in your while statement:

while((($rows=mysql_fetch_row($result))>$num    )){

This should be:

while(($rows=mysql_fetch_row($result))>$num){

In addition, at the end of your loop you are setting it back to 0:

if ($num == $max){
echo "</tr>";
$num = 0;#<------- RESETTING THE LOOP COUNTER
} 

You have a variable $row[pic] on line 21, i am guessing this is ment to be $rows[pic]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.