0

我需要使用一些 div 类将我的 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

请问有什么帮助吗?

4

1 回答 1

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);
?>
于 2012-12-03T02:30:31.450 回答