是叶子,还是旅行的风
- 人气
- 0
- 注册时间
- 2024-7-19
- 最后登录
- 2025-2-3
|
Discuz技巧
适用版本: |
DX早期版本 DX3.4 DX3.5 |
技巧类型: |
二开辅助 |
小时空Discuz教程可能涉及的数据库快速查询函数,请根据需要自行引用。
DSRC 即 DrawSnakeRunCore,是小时空DISCUZ及THINKPHP框架中二次封装的核心函数。本文仅罗列DSRC的Discuz版的部分代码。
- /*请求数据列表*/
- if(!function_exists('rc_getlist')){
- function rc_getlist($table,$con='',$order='',$page='1',$pagesize='999'){
- $page = intval($page);
- $page = ($page<1)?1:$page;
- $start = $pagesize * ($page-1);
- if($con){
- $con =" WHERE ".$con;
- }
- if($order){
- $order =" ORDER BY ".$order;
- }
- $result = DB::fetch_all("SELECT * FROM ".DB::table($table).$con.$order." LIMIT ".$start.",".$pagesize);
- return $result;
- }
- }
- /*请求数据数量*/
- if(!function_exists('rc_getcount')){
- function rc_getcount($table,$con='',$format=''){
- if($con){
- $con =" WHERE ".$con;
- }
- $result = DB::fetch_first("SELECT COUNT(*) AS num FROM ".DB::table($table).$con);
- if($format=='w'){
- if($result['num']>=10000) {
- $result['num'] = round($result['num'] / 10000, 1) . "<span style='font-size:12px;'>万</span>";
- }
- }
- return $result['num'];
- }
- }
- /*请求数据总和*/
- if(!function_exists('rc_getsum')){
- function rc_getsum($table,$field,$con='',$format=''){
- if($con){
- $con =" WHERE ".$con;
- }
- $result = DB::fetch_first("SELECT SUM(".$field.") AS num FROM ".DB::table($table).$con);
- if($format=='w'){
- if($result['num']>=10000) {
- $result['num'] = round($result['num'] / 10000, 1) . "<span style='font-size:12px;'>万</span>";
- }
- }
- return $result['num'];
- }
- }
- /*动态修改数据*/
- if(!function_exists('rc_dataplus')) {
- function rc_dataplus($table, $field, $con = '')
- {
- if ($con) {
- $con = " WHERE " . $con;
- }
- DB::query("UPDATE " . DB::table($table) . " SET " . $field . " = " . $field . " - (-1) " . $con);
- }
- }
- if(!function_exists('rc_dataminus')) {
- function rc_dataminus($table, $field, $con = '')
- {
- if ($con) {
- $con = " WHERE " . $con;
- }
- DB::query("UPDATE " . DB::table($table) . " SET " . $field . " = " . $field . " -1 " . $con);
- }
- }
- if(!function_exists('rc_datachange')) {
- function rc_datachange($table,$field,$change,$con=''){
- if($con){
- $con =" WHERE ".$con;
- }
- $cdr = -$change;
- DB::query("UPDATE ".DB::table($table)." SET ".$field." = ".$field." -".$cdr." ".$con);
- }
- }
- /*设置状态*/
- if(!function_exists('rc_status')) {
- function rc_status($table, $con = '', $status = '0')
- {
- if ($con) {
- $con = " WHERE " . $con;
- }
- $result = DB::query("UPDATE " . DB::table($table) . " SET status = '" . intval($status) . "' " . $con);
- }
- }
- /*请求单个数据(组)*/
- if(!function_exists('rc_getarray')) {
- function rc_getarray($table,$con='',$order=''){
- if($con){
- $con =" WHERE ".$con;
- }
- if($order){
- $order =" ORDER BY ".$order;
- }
- $result = DB::fetch_first("SELECT * FROM ".DB::table($table).$con.$order);
- return $result;
- }
- }
- /*请求单个数据*/
- if(!function_exists('rc_get')) {
- function rc_get($table,$field,$con='',$order=''){
- if($con){
- $con =" WHERE ".$con;
- }
- if($order){
- $order =" ORDER BY ".$order;
- }
- $result = DB::fetch_first("SELECT ".$field." FROM ".DB::table($table).$con.$order);
- return $result[$field];
- }
- }
- /*插入数据*/
- if(!function_exists('rc_insert')) {
- function rc_insert($table,$cs){
- return DB::insert($table,$cs,true);
- }
- }
- /*编辑数据*/
- if(!function_exists('rc_update')) {
- function rc_update($table,$cs,$bs){
- return DB::update($table,$cs,$bs);
- }
- }
- /*删除数据*/
- if(!function_exists('rc_delete')) {
- function rc_delete($table,$bs){
- return DB::delete($table,$bs);
- }
- }
复制代码
|
|