Welcome Guest, Not a member yet? Register   Sign In
How can i make model query based on images
#11

(08-21-2015, 08:04 AM)mwhitney Wrote:
(08-21-2015, 03:16 AM)freddy Wrote: by the way why you change query becom limit 2 mwhitney  all i want is take  4 data then my problem now is show the third and also 4 in other hand i have been tested it delete one when data still 4 it give me duplicate data which should only show data with row 3 then i delete again till data 2 it also duplicate, will you give me example how to show it with right ways

All I did was change the query to reflect what you were doing in the code by taking row_array(2) and row_array(3).

I think that we're running into a few different problems here simply because we're working off small snippets of code instead of the relevant controller, model, and view(s) and also dealing with a bit of a language barrier.

To go back to the original function you supplied:

PHP Code:
function lefttrend($art_slug)        

{
    return $this->db->query("SELECT * FROM `articles` WHERE art_slug != '$art_slug' and art_jenis='TREND' limit 1")


This could be modified as follows (using query builder because it makes more sense to me than manually editing a query string, especially with MySQL's syntax for this):

PHP Code:
function lefttrend($art_slug$limit 0$offset 0)        

{
    if ($limit 0) {
        if ($offset 0) {
            $this->db->limit($limit$offset);
        } else {
            $this->db->limit($limit);
        }
    }
    $this->db->where(array('art_slug !=' => $art_slug'art_jenis' => 'TREND'));

    return $this->db->get('articles');


Then you can get whatever range of values you need from the query by passing in the relevant $limit and $offset, or you can retrieve the full query results by leaving them out. So, you could get the first one by calling
PHP Code:
$first lefttrend($art_slug1
or get just the second and third by calling
PHP Code:
$twoThree lefttrend($art_slug21); 

Thanks mwhitney +1 and huge  Cool 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB