Page 1 of 1

php class return

Posted: Tue Oct 13, 2009 7:00 am
by Howl
Hello,

I'm kinda new to OOP PHP so this could be something easy to solve :)
I have here a class which fetches some rows in MySQL DB:

Code: Select all

<?php
        
    class Contact
    {
        
        public function get_Contact($cl_number,$contact_id){
                        
            if(isset($cl_number)){
                
                $sql = "SELECT * FROM tbl_client_contacts WHERE CUST_ID = '$cl_number' ";
                $query = mysql_query($sql);
                
                while($row = mysql_fetch_array($query)){
                    
                    $contact[] = $row;
                    
                }
                
                return $contact;
                
            }elseif(isset($contact_id)){
                
                $sql = "SELECT * FROM tbl_client_contacts WHERE CUST_ID = (SELECT CUST_ID FROM tbl_client_contacts WHERE ID = '$contact_id' ) ";
                $query = mysql_query($sql);
                
                while($row = mysql_fetch_array($query)){
                                                            
                    $contact[] = $row;
                    
                }
                
                return $contact;
                
            }
            
        }
                
    }
 
?>
this should return an array with values.
I would like to fetch these values but with an if(in_array())

Someone knows how to do this?

Thanks :)

Re: php class return

Posted: Tue Oct 13, 2009 7:06 am
by jackpf

Code: Select all

$contact = new Contact;
if(in_array('some_value', $contact->get_Contact('...')))
//...
Like that?

Re: php class return

Posted: Tue Oct 13, 2009 7:40 am
by Howl
Hi thanks for the reply.

Tried to that, didn't get any errors, but it doesn't work :(
Could I do it by returning an array?

Re: php class return

Posted: Tue Oct 13, 2009 8:39 am
by markusn00b
Howl wrote:Hi thanks for the reply.

Tried to that, didn't get any errors, but it doesn't work :(
Could I do it by returning an array?
Is your get_Contact() method returning results? Do a print_r($contacts->get_Contact(...)) to check what the method is returning.

Re: php class return

Posted: Tue Oct 13, 2009 8:53 am
by Howl
Then I get the values, something like this:

Code: Select all

Contact First Name: Array ( [0] => Array ( [0] => 1 [ID] => 1 [1] => Avril [FIRST_NAME]
At first sight there seems to be a problem with my array, no?