phpmysqlosclass

How can I get company accounts in osclass


My question is how can I get company accounts in osclass https://osclass.org


Solution

  • //connect with database
    $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$link) 
    {
        // can't connect to database
        $counter_connected = false;
        die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
        exit;
    }
    
    //write sql query 
    $sql = "SELECT pk_i_id FROM oc_t_user WHERE b_company = 1";
    mysqli_query($link, "SET NAMES 'utf8'");
    $res = mysqli_query($link, $sql);
    
    if (mysqli_num_rows($res) > 0)
    {
        while($row = mysqli_fetch_assoc($res)){
            $users_id[] = 'fk_i_user_id = ' .$row['pk_i_id'];
        }
    
        $cond = implode($users_id, ' OR ');
    
        //if you have country session (optional)
        if(empty($_SESSION['_country'])){
            $_SESSION['_country'] = 'SY';
        }
    
        $sql = "SELECT u.pk_i_id AS id, r.pk_i_id AS img_id, u.i_price, d.s_title, u.fk_c_currency_code, l.fk_c_country_code
                FROM oc_t_item u, oc_t_item_description d, oc_t_item_resource r, oc_t_item_location l
                WHERE d.fk_c_locale_code = '".osc_current_user_locale()."'
                AND ( ".$cond." )
                AND l.fk_c_country_code = '".strtoupper($_SESSION['_country'])."'
                AND l.fk_i_item_id = u.pk_i_id
                AND r.fk_i_item_id = u.pk_i_id
                AND d.fk_i_item_id = u.pk_i_id
                GROUP BY u.pk_i_id
                ORDER BY u.pk_i_id DESC
                LIMIT 12 ";
        //get the final results of all conditions    
        $users = mysqli_query($link, $sql);    
    }