CodeIgniter Forums

Full Version: why does this model work in PHP5 but not PHP4.4?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jng[/eluser]
I have made this on my mac, which I realized has the latest version of PHP so my guess is what this is not working?

To remove all the IF ELSE PHP logic from view, I moved it to the model, but maybe this logic is also wrong?

Basically any of the new properties like "foundclass", "hasTruppengattung", etc. don't show up on my webserver with PHP4 and instead just returns "Message: Undefined property: foundclass".

Thank you for any help you can provide.


Code:
<?php
class Bayern_model extends Model {
    
    function getAll() {

        
        $q = $this->db->query("SELECT * FROM people ORDER BY last_name");
        
        if($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
                
                $date = explode("-",$row->birthdate);
                //date("d M Y", mktime(0, 0, 0, $date[0], $date[1], $date[2]))
                
                $row->birthinfo = ($row->birthdate!="0000-00-00") ? "geb. " . date("d M Y", mktime(0, 0, 0, $date[1], $date[2], $date[0])) : "";
                $row->birthinfo .= ($row->birthplace!="") ? ", " . $row->birthplace : "";
                $row->foundclass = ($row->isFound) ? "found" : "notfound";                
                
                $row->hasTruppengattung = ($row->truppengattung!="") ? true : false ;
                $row->hasFormation = ($row->formation!="") ? true : false ;
                $row->hasTruppenteil = ($row->truppenteil!="") ? true : false ;        
                $row->hasServiceInfo = ( $row->hasTruppengattung || $row->hasFormation || $row->hasTruppenteil ) ? true : false ;
                
                
                $row->hasNotes = ($row->notes!="") ? true : false ;                
                $row->hasSource = ($row->sourceLink!="") ? true : false ;
                $row->hasScan = ($row->recordScan!="") ? true : false ;
                
                $row->searchURL = "http://mywebsite/?firstname" . $row->first_name . "&lastname;=" . $row->last_name;
                if($row->birthdate!="0000-00-00")
                    $row->searchURL .= "&birthyear;=" . $date[0];
            }
        return $data;
        }
    }
    
    
}

El Forum

[eluser]gyo[/eluser]
Do you have access to the PHP errors log?

El Forum

[eluser]jng[/eluser]
I don't think so, but I saw that Code Igniter can make its own error logs. Should I try that?

El Forum

[eluser]gyo[/eluser]
Maybe this is the problem... shouldn't the $data[] = $row; be at the end of your foreach?
As you do it now, $data doesn't contain any new values like 'foundclass' etc... because it's been set before they are declared.

Anyways, CodeIgniter only logs application related information, there's no php or mysql errors logged there.
You can still try switching your local webserver to PHP4 and test it there.

El Forum

[eluser]jng[/eluser]
Brilliant! Thanks a lot!

That was it! Funny how the newer version of PHP allows bad code. hehe. Cheers!

El Forum

[eluser]gyo[/eluser]
I think it doesn't work in both PHP4/5, but maybe you just have a different errors report setting.