Welcome Guest, Not a member yet? Register   Sign In
problem in listing category and subcategory in the same page
#11

[eluser]Nick_MyShuitings[/eluser]
Think it through again.... if you can make it happen in the controller you can also succeed in the view.

Why not put all of this:

Code:
echo ' ' .$lrow['id'].'   '. $lrow['heading'].'   ';
                $data['sub_listings_count'] = $this->Classifieds_model->count_classifieds($lrow['id']);
                print_r($data['sub_listings_count']).' <br/>';

Into a new variable $newshit['header'] = ..., $newshit['subcategories'] = ...,

Then run the foreach in your view.

Unless you get super lucky that someone here is so bored that they want to instantiate all of your code to fix it for you (very unlikely since your's isn't a bug or really anything to do with CodeIgniter but more you not knowing how to program => not as fun to troubleshoot), then you need to stop giving up so soon, and sit down and calmly plot out the logic of your foreach loops and what they need to do.
#12

[eluser]Bigil Michael[/eluser]
hi friend i have changed my controller like this

Code:
$build_array = array();
        $fleets = $this->Classifieds_model->select_all_classifieds();
        foreach($fleets as $row){
            $sub = $this->Classifieds_model->list_all_classifieds($row['id']);
            $build_array[] = array (
                'fleets_array' => $row,
                'listefleets_array' => $sub
            );
            foreach($sub as $subsub)
            {
                $this->data['k'] = $this->Classifieds_model->count_classifieds($subsub['id']);
            }
        }
        $meow = $build_array;
        $this->data['meow'] = $meow;

it is working fine

my view
Code:
&lt;?php foreach($meow as $crow){?&gt;
    &lt;?php echo $crow['fleets_array']['heading'];?&gt;
        &lt;?php
        foreach ($crow['listefleets_array'] as $lrow){?&gt;
            &lt;?php echo $lrow['heading'];?&gt; &lt;?php echo $k ?&gt;
        &lt;?php  } ?&gt;
&lt;?php } ?&gt;

now the problem is that it only prints the last result.

can anyone correct my problem???
thanks in advance......
#13

[eluser]Nick_MyShuitings[/eluser]
If you look in your controller, where you are setting $this->data['k'], you are overriding that each time. I think you'd be better off doing something like the following:

Code:
foreach($fleets as $row){
            $sub = $this->Classifieds_model->list_all_classifieds($row['id']);
            foreach($sub as $subsub)
            {
                $sub_sub[] = $this->Classifieds_model->count_classifieds($subsub['id']);
            }            
            $build_array[] = array (
                'fleets_array' => $row,
                'listefleets_array' => $sub
                'sub_sub' => $sub_$sub
            );
            
        }

that at least would contain all the data and you could get at it in your view however you need.
#14

[eluser]toopay[/eluser]
@Bigil MM :

I received your PM message, and please, stop doing that. I see Nick (even InsiteFX) already give you a suggestion, even give you a sample code. Working on it! We here just will give you a "guide" or "hint", you the one who should working on it!
#15

[eluser]Bigil Michael[/eluser]
controller modified like this
Code:
$build_array = array();
        $fleets = $this->Classifieds_model->select_all_classifieds();
        foreach($fleets as $row){
            $sub = $this->Classifieds_model->list_all_classifieds($row['id']);
            foreach($sub as $subsub)
            {
                $sub_result[] = $this->Classifieds_model->count_classifieds($subsub['id']);
            }
            $build_array[] = array (
                'fleets_array' => $row,
                'listefleets_array' => $sub,
                'list' => $sub_result
            );
            
        }
        $meow = $build_array;
        $this->data['meow'] = $meow;
it shows an error like this
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: sub_result

Filename: controllers/classifieds.php

Line Number: 58
#16

[eluser]Nick_MyShuitings[/eluser]
I'm gonna say this politely... Fucking check your fucking code!!!!

That means that there was no $sub returned, so it didn't enter into the foreach, and thus magically... $sub_result is not defined That is not a hard error message to debug... I refuse to believe you are anything but a troll if you keep posting ridiculous bullshit like this.

Seriously, at least try to decipher the CRYSTAL CLEAR error message PHP is giving you... so it has an undefined variable... fucking define it then, don't just blindly post to the forum...

I hope you learn to code at some point, but I'm done with you for now.

[edit]Those ###### are f U ckings... I think you deserve to know that... and I doubt your ability to have figured it out without me spelling it out for you.[/edit]
#17

[eluser]Bigil Michael[/eluser]
but it prints some result. so i think i am very near to the result

that's why i post the error
#18

[eluser]Nick_MyShuitings[/eluser]
Sigh, I lied, I'm not done with you yet.

Why might it print some results and not others you ask? because in your code you are never checking to see if your models calls return data.... you are just blindly assuming that they do and writing foreach loops all willy nilly.

Check your code, check what your models return, write catchs and failsafes, ifs etc... don't just blindly expect the result to be an array that you can iterate on.

And now I'm seriously done, cuz I'm falling asleep.
#19

[eluser]Bigil Michael[/eluser]
now i modified controller and model.
now all errors are corrected
controller
Code:
$build_array = array();
       $sub_result = array();
        $fleets = $this->Classifieds_model->select_all_classifieds();
        foreach($fleets as $row){
            $sub = $this->Classifieds_model->list_all_classifieds($row['id']);
            foreach($sub as $subsub)
            {
                $sub_result[] = $this->Classifieds_model->count_classifieds($subsub['id']);
            }
            $build_array[] = array (
                'fleets_array' => $row,
                'listefleets_array' => $sub,
                'list' => $sub_result
            );
        }
        $meow = $build_array;
        $this->data['meow'] = $meow;

model
Code:
function count_classifieds($parent=0)
    {
        $count=0;
        $result_total    =    $this->db->query("SELECT COUNT(id) AS total  FROM classifieds WHERE categoryid='$parent' AND status=1");
        if($result_total->num_rows()>0){
            $row    = $result_total->row();
            $count    =    $row->total;
        }
        return $count;
    }

view
Code:
&lt;?php foreach($meow as $crow){?&gt;
    &lt;?php echo $crow['fleets_array']['heading'];?&gt;
        &lt;?php
        foreach ($crow['listefleets_array'] as $lrow){?&gt;
            &lt;?php echo $lrow['heading'];?&gt;
                    &lt;?php foreach($crow['list'] as $krow) {
                        echo $krow;
                        }
                    ?&gt;
        &lt;?php  } ?&gt;
&lt;?php } ?&gt;

in the result page it prints like this
2
21
.
.
.
2110000000

if i remove this code
Code:
&lt;?php foreach($crow['list'] as $krow) {
                        echo $krow;
                        }
                    ?&gt;
and use only
Code:
(&lt;?php echo $crow['list']?&gt;)//[after making changes in controller]
then for each sub-subcategory it will print the same count

so. iam totally failed to solve this problem.
can anyone help me???
#20

[eluser]Bigil Michael[/eluser]
I've finally figured out how to work this!!
thanks for the advice guys!




Theme © iAndrew 2016 - Forum software by © MyBB