Welcome Guest, Not a member yet? Register   Sign In
20.03.19 Message: Object of class stdClass could not be converted to string
#1

(This post was last modified: 03-20-2019, 01:27 AM by Porto.)

Hello Guys, please i need a Light!

I've already read some cases identical as my issue here in the Forum, but i don't get STILL see what should i do.

The best answer was:
-------------------------------------------------------
eluser]Massaki[/eluser]

The variable $var is an object.

If you want to show an attribute from the object, then

Code:
echo $var->name_of_the_attribute
-------------------------------------------------------

But i still stuck.

I'm using this block of code from the documentation:
https://www.codeigniter.com/user_guide/d...esult-rows

This is my Controller/Method
_____________________________

Code:
        public function votecounting($page = 'vote_detail1')
        {
            if ( ! file_exists(APPPATH.'views/content/'.$page.'.php'))
                {
                       // Whoops, we don't have a page for that!
                       show_404();
                }
        
               $data['title'] = ucfirst($page); // Capitalize the first letter
            $data['totalrows'] = $this->Voting_counter_model->totalparticipants();

            $this->load->view('theme/header');
            $this->load->view('content/vote_detail1', $data);
            $this->load->view('theme/footer');
        }

This is my Model
_____________________________

Code:
    public function totalparticipants()
    {
        $query = $this->db->query("SELECT count(v_id) FROM ci_voting_counter WHERE v_column IN ('A', 'B', 'C', 'D', 'E')");

        $resultrows = $query->row();

        return $resultrows;
    }


This is my VIEW
_____________________________

Code:
  <div class="XXX">
       <span class="current">Votes<strong> <?php print_r($totalrows); ?></strong> </span>
   </div>
   
       <div class="block lrg">
           <div class="title">Vote results</div>
           <div class="info">The number who participated in the Vote yet <strong> <?php echo print_r($totalrows); ?> </strong> VOTER</div>

           <div class="info">The number who participated in the Vote yet <strong> <?php echo $totalrows; ?> </strong> VOTER</div>


If i try to show the variable this way:  <?php echo $totalrows; ?> i got the error message.

Code:
A PHP Error was encountered
Severity: 4096

Message: Object of class stdClass could not be converted to string

Filename: content/vote_detail1.php

Line Number: 24
Backtrace:

File: C:\xampp\htdocs\poll\application\views\content\vote_detail1.php
Line: 24

If i try to show the variable this way:  <?php echo $totalrows->v_id; ?> i got the error message.

Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: stdClass::$v_id

Filename: content/vote_detail1.php

Line Number: 24

This is the result of my First print_r() <?php print_r($totalrows); ?>
_____________________________

Code:
Votes stdClass Object ( [count(v_id)] => 498 )

This is the result of my Second print_r() <?php print_r($totalrows); ?>
_____________________________

Code:
The number who participated in the Vote yet stdClass Object ( [count(v_id)] => 498 ) 1 VOTER


What should i do please? v_id is the table_field_id and i just want to show a single row as explained in the documentation.

i've already tried using row_array(), But i stuck the same way.

Thank you so much in advance!
Reply


Messages In This Thread
20.03.19 Message: Object of class stdClass could not be converted to string - by Porto - 03-20-2019, 01:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB