• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Help to sort the items in shop system GeisorAAC

There should be query for listing items, add in the query
Code:
ORDER BY 'id' DESC
and it should work.
 
Yes i know how to do it in SQL but i dont know how to get it to work in PHP?
Code:
<?php
if(!defined('INITIALIZED'))
    exit;

if($config['site']['shop_system'])
{
    if($logged)
    {
        $user_premium_points = $account_logged->getCustomField('premium_points');
    }
    else
    {
        $user_premium_points = 'Login first';
    }
    function getItemByID($id)
    {
        $id = (int) $id;
        $SQL = $GLOBALS['SQL'];
        $data = $SQL->query('SELECT * FROM '.$SQL->tableName('z_shop_offer').' WHERE '.$SQL->fieldName('id').' = '.$SQL->quote($id).';')->fetch();
        if($data['offer_type'] == 'item')
        {
            $offer['id'] = $data['id'];
            $offer['type'] = $data['offer_type'];
            $offer['item_id'] = $data['itemid1'];
            $offer['item_count'] = $data['count1'];
            $offer['points'] = $data['points'];
            $offer['description'] = $data['offer_description'];
            $offer['name'] = $data['offer_name'];
        }
        elseif($data['offer_type'] == 'container')
        {
            $offer['id'] = $data['id'];
            $offer['type'] = $data['offer_type'];
            $offer['container_id'] = $data['itemid1'];
            $offer['container_count'] = $data['count1'];
            $offer['item_id'] = $data['itemid2'];
            $offer['item_count'] = $data['count2'];
            $offer['points'] = $data['points'];
            $offer['description'] = $data['offer_description'];
            $offer['name'] = $data['offer_name'];
        }
        return $offer;
    }

    function getOfferArray()
    {
        $offer_list = $GLOBALS['SQL']->query('SELECT * FROM '.$GLOBALS['SQL']->tableName('z_shop_offer').';');
        $i_item = 0;
        $i_container = 0;
        while($data = $offer_list->fetch())
        {
            if($data['offer_type'] == 'item')
            {
                $offer_array['item'][$i_item]['id'] = $data['id'];
                $offer_array['item'][$i_item]['item_id'] = $data['itemid1'];
                $offer_array['item'][$i_item]['item_count'] = $data['count1'];
                $offer_array['item'][$i_item]['points'] = $data['points'];
                $offer_array['item'][$i_item]['description'] = $data['offer_description'];
                $offer_array['item'][$i_item]['name'] = $data['offer_name'];
                $i_item++;
            }
            elseif($data['offer_type'] == 'container')
            {
                $offer_array['container'][$i_container]['id'] = $data['id'];
                $offer_array['container'][$i_container]['container_id'] = $data['itemid1'];
                $offer_array['container'][$i_container]['container_count'] = $data['count1'];
                $offer_array['container'][$i_container]['item_id'] = $data['itemid2'];
                $offer_array['container'][$i_container]['item_count'] = $data['count2'];
                $offer_array['container'][$i_container]['points'] = $data['points'];
                $offer_array['container'][$i_container]['description'] = $data['offer_description'];
                $offer_array['container'][$i_container]['name'] = $data['offer_name'];
                $i_container++;
            }
 
Last edited:
This:
Code:
$data = $SQL->query('SELECT * FROM '.$SQL->tableName('z_shop_offer').' WHERE '.$SQL->fieldName('id').' = '.$SQL->quote($id).';')->fetch();
Change to this:
Code:
$data = $SQL->query('SELECT * FROM '.$SQL->tableName('z_shop_offer').' WHERE '.$SQL->fieldName('id').' = '.$SQL->quote($id).' ORDER BY '.$SQL->fieldName('id').' DESC;')->fetch();

Should work.
 
If this won't work then hmm, it can be sth with this:
Code:
$offer_list = $GLOBALS['SQL']->query('SELECT * FROM '.$GLOBALS['SQL']->tableName('z_shop_offer').';');

Try to change it to:

Code:
$offer_list = $GLOBALS['SQL']->query('SELECT * FROM '.$GLOBALS['SQL']->tableName('z_shop_offer').' ORDER BY '.$SQL->fieldName('id').' DESC;');
 
Thanks but i tried that to but get error then, Fatal error: Call to a member function fieldName() on a non-object in line 47.
 
Yes, but i did mistake, and used $SQL instead of $GLOBAL['SQL'] xd
So correct line should looks like this:
Code:
$offer_list = $GLOBALS['SQL']->query('SELECT * FROM '.$GLOBALS['SQL']->tableName('z_shop_offer').' ORDER BY '.$GLOBALS['SQL']->fieldName('id').' DESC;');
 
Last edited:
Back
Top