sql >> Databasteknik >  >> RDS >> Mysql

MySQL - PHP:Visa resultat i tabellrader (5 resultat per rad)

    $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. Var klausul för att filtrera rader i MySQL

  2. När du använder MySQL's FOR UPDATE-låsning, vad är exakt låst?

  3. Java lagrad procedur vs PL/SQL lagrad procedur

  4. Skapa mysql-tabell automatiskt med StrongLoop