1
我想使用Php PDO数组。如何使用预定义开始和结束变量的循环显示整行?我不知道这是否有人问,但不能找到我的问题有关的东西现在使用计算出的开始和结束变量显示PDO数组对象
我的代码是这样的
$sql = 'SELECT `casino_id`,`kiosk_id`,`kiosk_name`,`place`,`city`,`groups` FROM kiosk_data WHERE 1';
$result=$setsu->prepare($sql);
$result->execute();
$dta=$result->fetchAll(PDO::FETCH_ASSOC);
$rwCnt=$result->rowCount();
$max=10;//display 10 records per page
$count = $rwCnt;
//$no is page no, which will determine which records to be shown on the current page
$start = ($no == 1)? 0 : ($no-1) * $max;
$end = ($no * $max);
$data="<table>";
for($i=$start;$i<$end;$i++){
if($i >= $count){break;}
$data.='<tr><td>'.$dta.'</td></tr>';
}
$data.="</table>";
echo $data;
样品的var_dump
array(3) {
[0]=> array(6) {
["casino_id"]=> string(1) "0"
["kiosk_id"]=> string(4) "1"
["kiosk_name"]=> string(5) "Tesla"
["place"]=> NULL ["city"]=> NULL
["groups"]=> NULL
}
[1]=> array(6) {
["casino_id"]=> string(1) "0"
["kiosk_id"]=> string(4) "2"
["kiosk_name"]=> string(6) "Espada"
["place"]=> NULL ["city"]=> NULL
["groups"]=> NULL
}
[2]=> array(6) {
["casino_id"]=> string(1) "0"
["kiosk_id"]=> string(4) "3"
["kiosk_name"]=> string(4) "Vlad"
["place"]=> NULL ["city"]=> NULL
["groups"]=> NULL
}
这工作,但怎么样我有10个更多的列,有没有一种方式没有指定列? – hikki 2015-02-23 06:41:57