2 回答
TA貢獻(xiàn)242條經(jīng)驗 獲得超128個贊
錯誤了!!!你的sql語句有問題吧!!!M('user')->where(array('id'=>mt_rand(0,999999)))->find();的意思是尋找id=0-999999中的隨意一個數(shù)據(jù)...但是你確定0-999999隨機一個你數(shù)據(jù)庫都有這個信息嗎??建議修改成
M('user')->where(array('id'=>1))->find(); id為1的數(shù)據(jù)總有吧!!!由于獲取不了數(shù)據(jù)..才會顯示undefined的!!!在使用thinkphp操作數(shù)據(jù)庫的時候..你可以根據(jù)返回的信息判斷一下是否獲取到數(shù)據(jù)的
TA貢獻(xiàn)8條經(jīng)驗 獲得超3個贊
別用M函數(shù),用<?php
namespace Admin\Model;
use Think\Model;
class PostsModel extends Model {
?? ?
??? protected $tableName = "posts";
?? ?
??? protected $_validate = [
??????? ['p_title', 'require', "標(biāo)題不能為空"],
??????? ['p_content', 'require', "內(nèi)容不能為空"],
??? ];
?? ?
?? ?
??? public function pagelist($page, $perPage) {
??????? $count = $this->count();
??????? $row = $this->page($page, $perPage)->select();
??????? return [$count, $row];
??? }
}這種方式!
- 2 回答
- 0 關(guān)注
- 2718 瀏覽
添加回答
舉報
