我尝试从数组 def index
if params[:topic_id].present?
@posts = @topic.posts.all
else
@posts = Post.includes(:topic).references(:topic).all
@posts = @posts.order('topics.name desc')
end
if (Time.zone.parse(params[:start_date]) rescue nil).present? && (Time.zone.parse(params[:end_date]) rescue nil).present?
@posts = @posts.sort_by_time(params[:start_date], params[:end_date])
else
@posts = @posts.sort_by_time(Date.yesterday.to_s, Date.today.to_s)
end
@posts = @posts.eager_load(:ratings, :comments, :user, :users).paginate(page: params[:page], per_page: 10)
@tags = Tag.all
end
def read
@post.users << current_user unless @post.users.include?(current_user)
end
中获取随机值
我的插入行看起来不错
':server' => $gg
但是我的价值代码有很多错误,使页面说当前无法处理此请求。
$insertLogSQL -> execute(array(
':user' => $_SESSION['username'],
':ip' => $host,
':port' => $port,
':time' => $time,
':method' => $method,
':stopped' => 0,
':server' => $gg));`
错误是:
通知:未定义变量:第63行的C:\ xampp \ htdocs \ New \ boot.php中的赢家
致命错误:未捕获的PDOException:SQLSTATE [23000]:违反完整性约束:1048列“服务器”无法在C:\ xampp \ htdocs \ New \ boot.php:63
中为null 堆栈跟踪:// the array $arrX = array("Kay", "Joe","Susan", "Frank"); // get random index from array $arrX $randIndex = array_rand($arrX); $gg = $arrX[$randIndex];