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)