2012-12-03 37 views
0

我需要將我的PHP數組轉換爲具有某個div類的html。將PHP數組轉換爲html

這裏是我的代碼:

<?php 
$con = mysql_connect("localhost","root","root"); 
if (!$con) 
    { die('Could not connect: ' . mysql_error()); 
    } 
mysql_select_db("asd", $con); 

$result = mysql_query("SELECT * FROM asd"); 
$something = array(); 
while ($row = mysql_fetch_assoc($result)) { 
$something[] = array("title"=>$row['title'], 
     "name"=>$row['name'], 
     "content"=>$row['content'], 
     "image" => 
      array(
      "cls"=>"slide-image", 
      "_src"=>$row['src'], 
      "source"=>$row['source']     
      ) 
     ); 
} 
mysql_close($con); 
?> 

我想這樣

<div class="class1"> Here title goes</div> 
Here name with some class 
Here content with some class 

任何幫助輸出嗎?

+1

你嘗試過什麼嗎? – GolezTrol

+0

while($ row = mysql_fetch_assoc($ result)){ echo「{$ row}」; } 我不知道它是正確還是錯誤。 – user1868475

+0

你必須print_r($ row)或者說你想要哪一行索引。 echo $ row ['id_column']; –

回答

0
<?php 
mysql_connect("localhost","root","root") or die (mysql_error()); 
mysql_select_db("asd") or die (mysql_error()); 

$result = mysql_query("SELECT * FROM asd") or die (mysql_error()); 
while ($row = mysql_fetch_array($result)) { 
     $title = $row['title']; 
     $name = $row['name'] ; 
     $content = $row['content']; 
     echo "<div class=title>" . $title . "</div>"; 
} 
mysql_close($con); 
?> 
+0

它顯示div,但沒有合適的行值。 – user1868475

+0

你是否收到任何錯誤 – Yamaha32088

+0

它顯示沒有錯誤。 – user1868475