表 users 有 14 列 - id, src link, title...
function get_atitles(){
global $db;
$st = $db->query("select * from users order by name asc");
$arr = $st->fetchAll();
$ht = '';
foreach($arr as $el){
$ht .= "<div class='atitle' data-id= " . $el['id'] . " data-src='" . $el['src'] . "... and so on for all of the 14 columns...>" . $el['title'] . "</div>\n";
}
echo $ht;
}
有没有更短的方法,像这样:
foreach($arr as $el){
$ht .= "<div class='atitle'
//foreach column in users $ht .= "data-" . column_name = column_value
$ht .= ">" . $el['title'] . "</div>\n";
}
HUX布斯