php class return

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Howl
Forum Newbie
Posts: 3
Joined: Tue Oct 13, 2009 6:57 am

php class return

Post 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 :)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: php class return

Post by jackpf »

Code: Select all

$contact = new Contact;
if(in_array('some_value', $contact->get_Contact('...')))
//...
Like that?
Howl
Forum Newbie
Posts: 3
Joined: Tue Oct 13, 2009 6:57 am

Re: php class return

Post 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?
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: php class return

Post 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.
Howl
Forum Newbie
Posts: 3
Joined: Tue Oct 13, 2009 6:57 am

Re: php class return

Post 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?
Post Reply