Welcome Guest, Not a member yet? Register   Sign In
You probably get this one..?
#1

[eluser]developer10[/eluser]
Why can't i get my bid count in my view:

model:
Code:
function getSviProjekti()
    {
        $data = array();
        
        $this->db->join('job_kategorije', 'job_kategorije.kat_id = job_projekti.kat_id', 'left');
        $this->db->join('job_podkategorije', 'job_podkategorije.podkat_id = job_projekti.podkat_id', 'left');
        $this->db->join('users', 'users.id = job_projekti.aut_id', 'left');
        $this->db->order_by('job_projekti.pro_id', 'desc');
        $query = $this->db->get('job_projekti');
        
        if ($query->num_rows() > 0)
        {
            $projekti = $query->result_array();
            
            foreach ($projekti as $row)
            {
                $broj = $this->db->count_all_results('job_ponude', array('pro_id' => $row['pro_id']));
                
                $data = $broj;
            }
            
            $data = $projekti;
        }
        
        return $data;
    }

view
Code:
foreach($rSet as $key => $value):
    echo '<p>';
    echo '<b>Projekt #'.$value['pro_id'].'</b> <br />';
    echo 'Poslodavac: <b>'.$value['username'].'</b> | Ponuda za ovaj projekt: ';
    
    echo $value['broj'];
/*
        foreach ($value as $row):
            echo $row['broj'];
        endforeach;
*/
    
    echo '<br />';
    echo anchor('projekti/'.$value['seo_naslov'].'/', $value['naslov']) . '<br />';

controller:

Code:
function index()
    {    
        $data['rSet'] = $this->projekti->getSviProjekti();
        
        $this->template->write('naslov', 'Vidi sve projekte');
        $this->template->write_view('lijevo', 'lijevoView', $data);
        $this->template->write_view('sadrzaj', 'projekti/projektiView', $data);
        $this->template->write_view('goredole', 'goredoleView', $data);
        $this->template->render();
    }
#2

[eluser]Rolly1971[/eluser]
in your foreach loop you set $data = $broj on every iteration. on the next iteration since you do not do anything with $broj the data is lost even though you set $data to = $broj every loop and once your loop is done any information in the $data variable is lost when you set it to:

$data = $projeckti;

after the loop is done.

try something like this:

Code:
$i = count($projekti);
for ($j = 0; $j < $i; $j++)
{
  $projekti[$j]['count'] = $this->db->count_all_results('job_ponude', array('pro_id' =>  $projekti[$j]['pro_id']));
}

return $projekti;
#3

[eluser]developer10[/eluser]
[quote author="Rolly1971" date="1285632454"]in your foreach loop you set $data = $broj on every iteration. on the next iteration since you do not do anything with $broj the data is lost even though you set $data to = $broj every loop and once your loop is done any information in the $data variable is lost when you set it to:

$data = $projeckti;

after the loop is done.

try something like this:

Code:
$i = count($projekti);
for ($j = 0; $j < $i; $j++)
{
  $projekti[$j]['count'] = $this->db->count_all_results('job_ponude', array('pro_id' =>  $projekti[$j]['pro_id']));
}

return $projekti;
[/quote]


well u tried that but nothing happens nor changes

look, i need to have it like this:

Project id: [value]
Project name: [value]
Bid Count: [number] this is the number i'm trying to get
Project ends: [value]

I'm able to get all the values by $projekti = $query->result_array();

but i need that count to display number of bids for each project.

Now i dont understand how should i modify the view file in order to utilise the code you gave to me (maybe it does work but, i didnt change my view)
#4

[eluser]John_Betong[/eluser]
Play about with this:
Code:
// in you Model
if ($query->num_rows() > 0)
{
  $projekti = $query->result_array();
      
  foreach ($projekti as $row)
  {
    $broj = $this->db->count_all_results('job_ponude', array('pro_id' => $row['pro_id']));

    // Debug: remove rem on next line to see the count_all_result()
    // echo '<br />' .$broj;

    $data['broj'][] = $broj;
  }
            

// in you View
  foreach($broj as $detail => $row):
    echo '<br />details: ', $detail;
    echo '<br />row:     ', $row;
  endforeach;
&nbsp;
&nbsp;
&nbsp;
#5

[eluser]developer10[/eluser]
[quote author="John_Betong" date="1285659669"]Play about with this:
Code:
// in you Model
if ($query->num_rows() > 0)
{
  $projekti = $query->result_array();
      
  foreach ($projekti as $row)
  {
    $broj = $this->db->count_all_results('job_ponude', array('pro_id' => $row['pro_id']));

    // Debug: remove rem on next line to see the count_all_result()
    // echo '<br />' .$broj;

    $data['broj'][] = $broj;
  }
            

// in you View
  foreach($broj as $detail => $row):
    echo '<br />details: ', $detail;
    echo '<br />row:     ', $row;
  endforeach;
[/quote]

I tried your code but still not getting the counted value.

Variable $data should carry to view both $projekti variable and counted variable. So, how to merge these values into $data:

Code:
$data = $projekti // from main query (main rows)
$data = /* counted value from foreach loop inside the model */
$data['broj'][] = $broj; // this was your example but it seems not to work :(

Thanks for trying though. Hope something else crosses your ming, or way to work this out?
#6

[eluser]developer10[/eluser]
Well, i think i finally found a good solution, and yet very simple:
In my view, at the point i want my bid count to appear:

Code:
echo $this->ponude->countPonude($value['pro_id']);

I call this function from a model related to bids.
But maybe for many of you it is bad practice to call models from a view?




Theme © iAndrew 2016 - Forum software by © MyBB