Welcome Guest, Not a member yet? Register   Sign In
Sorting an Array with Objects
#11

[eluser]elaniobro[/eluser]
This is a sql result. I thought I already was doing such via my for loop.

To recap, when I do the following:

Code:
<?php
        
            #print_r ($query->result());
            $input = $query->result();
            $result= array_reverse($input);


            foreach($result as $row):?>
            <div class="trigger">          
            <p class="resume_date">&lt;?=$row->date?&gt;</p>  
            <h2 class="resume_company"><a href="#">&lt;?=$row->company?&gt;</a> </h2>
            </div>
            <div class="toggle_container">
                <div class="block">
                        <h1 class="resume-title">&lt;?=$row->job_title?&gt;</h1>
                    &lt;!--Content--&gt;
                        <p class="resume-location">&lt;?=$row->location?&gt;</p>
                        <div class="clear"></div>
                        <p class="resume-content">&lt;?=$row->description?&gt;</p>
                        <br />
                </div>
            </div>
                         <div class="clear"></div>

        &lt;?php endforeach;?&gt;

the results are displayed like so:
id=>90
id=>80
id=>70
id=>4
id=>5

when I need it to be displayed like so:
id=>4
id=>5
id=>90
id=>80
id=>70

It is just displaying the order of how they appear in the database.
#12

[eluser]danmontgomery[/eluser]
Code:
$this->db->order_by('id ASC');
#13

[eluser]elaniobro[/eluser]
[quote author="noctrum" date="1268103643"]
Code:
$this->db->order_by('id ASC');
[/quote]

That would then go in the controller as such?
Code:
$data['query'] = $this->db->get('resume');
            $this->db->order_by('id ASC');
#14

[eluser]danmontgomery[/eluser]
It needs to go before get()

Code:
$this->db->order_by('id ASC')->get('resume');

http://ellislab.com/codeigniter/user-gui...ecord.html
#15

[eluser]elaniobro[/eluser]
[quote author="noctrum" date="1268104154"]It needs to go before get()

Code:
$this->db->order_by('id ASC')->get('resume');

http://ellislab.com/codeigniter/user-gui...ecord.html[/quote]

Yes, I was just reading that page.

Sheer genius when you see it spelled out, this makes total sense. Now I am about to go db sorting crazy! Thanks once again Noctrum.
#16

[eluser]elaniobro[/eluser]
noctrum

I have another question. In my controller I have the following query:
Code:
$data['built_date'] = $this->db->order_by('date DESC LIMIT 1')->get('thoughts');

I am trying to echo the date field of my database in the view as such:

Code:
<lastBuildDate>&lt;?php print_r( $built_date->result('WHERE date'));?&gt;
</lastBuildDate>

I have tried doing 'date', but all my iterations and variants produce the same result:

Code:
<lastBuildDate>Array
(
    [0] => Array
        (
            [id] => 9
            [title] => My Title
            [body] => Lorem Ipsum Dolor
            [tag] => Nine-to-Five
            [date] => 2010-03-15 18:51:04
        )

)</lastBuildDate>

How can I make it so that the following is shown?


Code:
<lastBuildDate>2010-03-15 18:51:04</lastBuildDate>

?? I am stuck, and have tried multiple things with fail.




Theme © iAndrew 2016 - Forum software by © MyBB