sql >> Database >  >> RDS >> Mysql

MySQL - PHP:resultaten weergeven in tabelrijen (5 resultaten per rij)

    $query = mysql_query("SELECT * FROM gallery WHERE gallery_number='$gallery_number'");

    echo '<table width="960">';
    $i = 0; //first, i set a counter 
    while($fetch = mysql_fetch_assoc($query)){
    //counter is zero then we are start new row  
        if ($i==0){
            echo '<tr>';
        }
        //here we creating normal cells <td></td>
        $image_name = $fetch['image_name'];
        $image_location = $fetch['image_location'];
        echo '<td>'.'<img src="'.$image_location.'" alt="'.$image_name.'"/>'.'</td>';   
        //there is a magic - if our counter is greater then 5 we set counter to zero and close tr tag  
        if ($i>5){
            $i=0;
            echo '</tr>';
        };  
        $i++; //$i = $i + 1 - counter + 1
    }
    echo '</table>';  



  1. PHP SQL STMT SELECTEER meerdere LIKE? is dit mogelijk?

  2. Ondersteuning voor meerdere talen in 11i/R12

  3. SQLite-queryresultaten opmaken als een door komma's gescheiden lijst

  4. MySQL vs MongoDB 1000 leest