moungoDB 语法
SQL查询语句 Mongo查询语句
CREATE TABLE USERS (a Number, b Number) 隐式的创建,或 MongoDB::createCollection().
INSERT INTO USERS VALUES(,) $db->users->insert(array("a" => , "b" => ));
SELECT a,b FROM users $db->users->find(array(), array("a" => , "b" => ));
SELECT * FROM users WHERE age= $db->users->find(array("age" => ));
SELECT a,b FROM users WHERE age= $db->users->find(array("age" => ), array("a" => , "b" => ));
SELECT a,b FROM users WHERE age= ORDER BY name $db->users->find(array("age" => ), array("a" => , "b" => ))->sort(array("name" => ));
SELECT * FROM users WHERE age> $db->users->find(array("age" => array('$gt' => )));
SELECT * FROM users WHERE age< $db->users->find(array("age" => array('$lt' => )));
SELECT * FROM users WHERE name LIKE "%Joe%" $db->users->find(array("name" => new MongoRegex("/Joe/")));
SELECT * FROM users WHERE name LIKE "Joe%" $db->users->find(array("name" => new MongoRegex("/^Joe/")));
SELECT * FROM users WHERE age> AND age<= $db->users->find(array("age" => array('$gt' => , '$lte' => )));
SELECT * FROM users ORDER BY name DESC $db->users->find()->sort(array("name" => -));
CREATE INDEX myindexname ON users(name) $db->users->ensureIndex(array("name" => ));
CREATE INDEX myindexname ON users(name,ts DESC) $db->users->ensureIndex(array("name" => , "ts" => -));
SELECT * FROM users WHERE a= and b='q' $db->users->find(array("a" => , "b" => "q"));
SELECT * FROM users LIMIT , $db->users->find()->limit()->skip();
SELECT * FROM users WHERE a= or b= $db->users->find(array('$or' => array(array("a" => ), array("b" => ))));
SELECT * FROM users LIMIT $db->users->find()->limit();
EXPLAIN SELECT * FROM users WHERE z= $db->users->find(array("z" => ))->explain()
SELECT DISTINCT last_name FROM users $db->command(array("distinct" => "users", "key" => "last_name"));
SELECT COUNT(*y) FROM users $db->users->count();
SELECT COUNT(*y) FROM users where AGE > $db->users->find(array("age" => array('$gt' => )))->count();
SELECT COUNT(AGE) from users $db->users->find(array("age" => array('$exists' => true)))->count();
UPDATE users SET a= WHERE b='q' $db->users->update(array("b" => "q"), array('$set' => array("a" => )));
UPDATE users SET a=a+ WHERE b='q' $db->users->update(array("b" => "q"), array('$inc' => array("a" => )));
DELETE FROM users WHERE z="abc" $db->users->remove(array("z" => "abc"));
会员反馈功能
web leaf/leaf/feedback.php
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/bootstrap.min.css") ;?>"/>
<link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/mobile-style.css") ;?>">
<link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/sweetalert.css") ;?>">
<title></title>
</head>
<body>
<header class="personal_center_header">
<div >
<a href="#" ><i><img src="<?php echo TPLURL ;?>assets/img/1_03.png" alt="" /></i><p>意见反馈</p><img src="<?php echo TPLURL ;?>assets/img/1_03.gif" alt=""/></a>
</div>
</header>
<article class="feedback_article apply_agent_article">
<form id="form-feedback">
<label><small>请留下您宝贵的意见</small></label>
<textarea placeholder="您想对我们说点什么......" name="explain" id="explain"></textarea>
<div class="address">
<small>付款截图上传</small>
<p>
<input type="file" name="pic" id="pic" class="file"/>
<strong>浏览图片</strong>
</p>
</div>
<button type="submit">确认提交</button>
</form>
</article>
<footer class="personal_center_footer">
</footer>
<script type="text/javascript" src="<?php echo assets(TPLURL . 'assets/js/jquery-2.1.3.min.js') ;?>"></script>
<script type="text/javascript" src="<?php echo assets(TPLURL . 'assets/js/bootstrap.min.js') ;?>"></script>
<script type="text/javascript" src="<?php echo assets(TPLURL . 'assets/js/sweetalert.min.js') ;?>"></script>
<script type="text/javascript" src="<?php echo assets(TPLURL . 'assets/js/common.js') ;?>"></script>
<script type="text/javascript" src="<?php echo assets(TPLURL . 'assets/js/feedback.js') ;?>"></script>
</body>
</html>
ajax 提交]
/**
* public common
* $ mod_reg 2013-06-07 00:09:13
* @author Changhe<xuwu125@gmail.com>
*/
$(function(){
feedback_init();
});
function feedback_init(){
$('#form-feedback').submit(function(){
var senddata={
explain:$('#explain').val(),
pic:$('#pic').val(),
};
if(senddata.explain.length<=){
alert("您宝贵的的意见不能少于10个汉字");
return false;
}
//连接到 _mod_mod_feed
var url='/feed/add.html?ajax=json&r='+random();
$.post(url, $(this).serialize(), function(data){
if(data.error == ){
alert(data.message);
}else{
swal(data.message);
}
});
return false;
});
}
ajax传到—mod/mod_feed.php
切忌:定义了一定要在 index。php下面配置
class mod_feed extends mobileweixin{
/**
* 意见反馈
**/
public function feed_init() { }
public function action_add() {
if($_GET['ajax'] == 'json'){
$post = $_POST;
$data=array(
'explain'=>trim($_POST['explain']),
'pic'=>trim($_POST['pic']),
'status'=>FeedbackModel::Notviewed,
'AppID'=>appid(),
);
if(empty($data['explain'])){
$this->_alert(ERROR, "您宝贵的的意见不能少于10个汉字");
}
$FeedbackModel = new FeedbackModel($data);
$FeedbackModel->save();
}
}
}
手机提交完成
后台管理—data/cpapp_nav.php添加目录
在_mod/mod_app.php 定义
public function action_feedback() {
import('org.mod.feedback');
$app=new feedback($this);
$method_name='on_'.$this->_CF['type'];
if(method_exists($app, $method_name)){
$app->$method_name();
}else{
$this->_alert(ERROR, PARAM_ERROR);
}
}
里面引入了 system/org/mod/class.feedback.php
<?php
/**
* @用户反馈
* @author qy
* @time 2015-06-05
*/
import ( 'org.mod.ModPublic' );
class feedback extends ModPublic {
private $tab_feedback;
// 实例化 引入
function app_init() {
$this->tab_feedback = $this->mongodb ()->feedback;
$this->t->_view ['extcss'] = array (
'ext_agent'
);
$this->t->_view ['extjs'] = array (
'ext_agent'
);
}
/**
* @功能:反馈信息
* @return void
* @author qy
*
*/
public function on_index() {
$feedback = FeedbackModel::orderBy("status",)->orderBy("_id",-)->get();
$this->t->_view ['datalist'] = $feedback;
}
public function on_read() {
$id = intval($_GET['id']);
if(!$id){
$this->_alert(ERROR, '参数错误');
}
//查找ID下 对应的参数
$feedback = FeedbackModel::find ($id);
if (isset ( $_GET['id'] ) && intval ( $_GET['id'] )) {
$info = FeedbackModel::find($_GET['id']);
$info ->status = ;
$info->save();
}
//显示详情
$this->t->_view ['datalist'] = $feedback;
}
}
?>
FeedbackModel::这个是自定义了参数
特别注意 Notviewed 的引入
class FeedbackModel extends MongoLModel
{
public $collectionName = "feedback";
const Notviewed = ; //0未查看 1已查看
//自动递增
public $autoIncrement = true;
//时间戳
public $timestamp = true;
}