{
$array
=
array
();
$result
=mysql_query(
$sql
);
$i
=0;
while
(
$row
=mysql_fetch_assoc(
$result
))
{
$array
[
$i
]=
$row
;
$i
++;
}
return
$array
;
}
//$con
的几种情况
//
空:返回全部记录
//array:eg. array('id'=>'1') 返回 id=1
的记录
//string :eg. 'id=1' 返回 id=1
的记录
function
toExtJson(
$table
,
$start
="0",
$limit
="10",
$cons
="")
{
$sql
=
$this
->generateSql(
$table
,
$cons
);
$totalNum
=
$this
->findCount(
$sql
);
$result
=
$this
->findBySql(
$sql
." LIMIT ".
$start
." ,".
$limit
);
$resultNum
=
count
(
$result
);
//
当前结果数
$str
="";
$str
.= "{";
$str
.= "'totalCount':'$totalNum',";
$str
.="'rows':";
$str
.="[";
for
(
$i
=0;
$i
<
$resultNum
;
$i
++){
$str
.="{";
$count
=
count
(
$result
[
$i
]);
$j
=1;
foreach
(
$result
[
$i
]
as
$key
=>
$val
)
{
if
(
$j
<
$count
)
{
$str
.="'".
$key
."':'".
$val
."',";
}
elseif
(
$j
==
$count
)
{
$str
.="'".
$key
."':'".
$val
."'";
}