N
N
Night3862021-10-10 22:09:30
PHP
Night386, 2021-10-10 22:09:30

How to create an object count function?

Good evening, there is such a code - tell me how you can display the number of objects per page? with var dump\print_r null everywhere

public function display()
    {
      if (isset($_POST['fav']))
      {
        $id = (int)$_POST['fav'];

        if ($id<=0) die;
        
        $chk = (bool)db::i()->selectCell("SELECT added from c_user_favorite where id_user = ".(int)$this->user['id']." and id_object = ".(int)$id.";");

        if ($chk) db::i()->query("DELETE from c_user_favorite where id_user = ".(int)$this->user['id']." and id_object = ".(int)$id.";");
        else db::i()->query("INSERT INTO c_user_favorite (id_user, id_object, added) VALUES (".(int)$this->user['id'].", ".(int)$id.", NOW());");
      }
      else
      {
        tpl::i()->load('auth');
        

        /* select rows */


        $favIds = db::i()->selectArr("SELECT id_object AS _V FROM c_user_favorite where id_user = ".(int)$this->user['id']);

        if (count($favIds))
        {
          route::need('fs');

          $orders = array
          (
            '__photoid' => 'ФОТО', 
            'id' => 'ID', 
            '__l_deal_type__name' => 'СДЕЛКА', 
            'address' => 'АДРЕС', 
            'name' => 'НАЗВАНИЕ', 
            '__l_object_type__name' => 'ТИП ОБЪЕКТА', 
            '__l_object_metro__name' => 'МЕТРО', 
            'area' => 'МЕТРАЖ', 
            '__price' => 'ЦЕНА', 
            '__c_user_favorite__added' => 'ДОБАВЛЕНО'
          );
          
          
      
          tpl::i()->set('orders', $orders);
          tpl::i()->set('rows', fs::getObjects("c_object.id IN (".implode(",", $favIds ).") and c_object.id>0"));
        }

        tpl::i()->display();
      }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Keliorw, 2021-10-11
@Keliorw

Such things are usually written in the file itself at the place where you need the output of the variable you need, but you have a fucking tpl, so you can come up with such a crutch as a variant.

$CurrentPage = file_get_contents("/tpl/auth.tpl");
$result = "Название переменной = ".$favIds.$CurrentPage;
file_put_contents("/tpl/auth.tpl", $result);

PS I don’t know how variables are declared on tpl, so you’ll add it yourself, but the point is that you read the file into a line, then add a variable declaration to the beginning of this line, and this declared variable must already be written in advance where you want to see it output in the tpl file where you write it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question