2017-04-12 70 views
-1

我需要製作一張表格,每行最好4-5張圖片,而不是我的頁面。任何幫助,將不勝感激Php圖庫表

<?php 
$host = "localhost"; 

$user = "root"; 
$password = ""; 
$database = "imageupload"; 

$query = "SELECT id, url, name from images "; 

$connect = mysqli_connect($host,$user,$password,$database) or die("Problem connecting."); 
$result = mysqli_query($connect,$query) or die("Bad Query."); 

mysqli_close($connect); 

while($row = $result->fetch_array()) 
{ 

    echo "<td>"; 

    echo "<td><h2><img src=" . $row['url'] . " width=150 height=150/></h2></td>"; 


    echo "<td><h2>" .$row['name'] . "</h2></td>"; 


    echo "</td>"; 
} 
?> 

<table> 
+0

您已經包含一些代碼,看起來像它試圖做你需要做什麼。它有什麼作用? –

+0

你太早關閉了你的連接 –

+0

和你的'

'標籤不合適。語法:'
...
'。 '''是你的代碼。 –

回答

-1

你可以試試這個:

echo "<table><tr>"; 
foreach($row = $result->fetch_array()) { 
    if($row['id'] % 4 == 0) { //Change it to 5 if you want 5 images per row 
     echo "</tr><tr>"; 
    } 
    echo "<td><img src='" . $row['url'] . "' /></td>"; 
} 
echo "</tr></table>";