From 27106f39c4611c3a446c9cef0519f83ff56c7c4d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 10 Nov 2013 12:31:08 +0100 Subject: [PATCH] random improvement --- htdocs/application/controllers/api.php | 7 ------- htdocs/application/models/pastes.php | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/htdocs/application/controllers/api.php b/htdocs/application/controllers/api.php index 3b3703c..a284d00 100644 --- a/htdocs/application/controllers/api.php +++ b/htdocs/application/controllers/api.php @@ -100,13 +100,6 @@ class Api extends Main { $this->load->model('pastes'); $data = $this->pastes->random_paste(); - - if (!$data) - { - $data = array( - 'message' => 'Please try again', - ); - } echo stripslashes(json_encode($data)); } } diff --git a/htdocs/application/models/pastes.php b/htdocs/application/models/pastes.php index f8a00f0..2200dec 100644 --- a/htdocs/application/models/pastes.php +++ b/htdocs/application/models/pastes.php @@ -583,8 +583,8 @@ class Pastes extends CI_Model function random_paste() { $this->load->library('process'); - $paste_id = rand(1, $this->countPastes()); - $this->db->where('id', $paste_id); + $this->db->order_by('id', 'RANDOM'); + $this->db->limit(1); $query = $this->db->get('pastes'); if ($query->num_rows() > 0)