示例#1
0
文件: sql.php 项目: riking/Shokregate
function sql2json($data_sql)
{
    $json_str = "";
    if ($total = sqlRows($data_sql)) {
        if ($total > 1) {
            $json_str .= "{\"___\":[";
        }
        $row_count = 0;
        while ($data = sqlArray($data_sql)) {
            if (count($data) > 1) {
                $json_str .= "{";
            }
            $count = 0;
            foreach ($data as $key => $value) {
                if (count($data) > 1) {
                    $json_str .= "\"" . $key . "\":";
                }
                if (is_string($value)) {
                    $json_str .= "\"";
                    $value = escapeJsonString($value);
                }
                $json_str .= $value;
                if (is_string($value)) {
                    $json_str .= "\"";
                }
                $count++;
                if ($count < count($data)) {
                    $json_str .= ",";
                }
            }
            $row_count++;
            if (count($data) > 1) {
                $json_str .= "}";
            }
            if ($row_count < $total) {
                $json_str .= ",";
            }
        }
        if ($total > 1) {
            $json_str .= "]}";
        }
    } else {
        $json_str = "{}";
    }
    return $json_str;
}
示例#2
0
<?php

include "../function.php";
$url = "?page=";
$page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
$pagesize = 20;
$sql = "select t.param_key, t.param_value, t.id from " . $mysqlConfig["db_perfix"] . "param t order by t.id desc";
//获取总数
$totalCount = sqlCount($sql, "", "", "t.id");
$pageCount = ceil($totalCount / $pagesize);
$limit = " limit " . ($page - 1) * $pagesize . " , " . $pagesize;
$rs = sqlArray($sql . $limit);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php 
//导入meta数据及js库
echo $systemHead["meta"] . $systemHead["title"] . CSS_BASE . JS_JQUERY . JS_DIALOG . JS_BASE . JS_COMMON . KINDEDITOR . LIB_LIGERUI;
?>




<style>
body{ background:#FFF}
.grid tr{ height:30px; border-bottom:1px #999 dotted}
.grid th{ text-align:center; background:#F2F2F2; font-weight:bold; border-right:1px #999 dotted }
.grid td a{text-decoration:none}
.grid td{ border-right: 1px #999 dotted }
.l-table-edit {}
示例#3
0
 public function getNewsById($id)
 {
     $sql = "select * from " . $this->mysqlConfig["db_perfix"] . "web_news where id = {$id} order by id desc";
     return sqlArray($sql);
 }