new to php - please help

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
unkempt
Forum Newbie
Posts: 6
Joined: Tue Mar 25, 2008 5:20 pm

new to php - please help

Post by unkempt »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi - i am using flash with php and amfphp

here is an example of my code:
what i want to do is pass another variable to the function aswell as $live - so that the "FROM staff" can instead be told which table to select from i.e "FROM another_table", basically i want to pass to it the table to select from i.e "another_table" or "yet_another_table"

so in short instead of "staff" being hardcoded - i want to pass the table to select from
hope you can help

Code: Select all

function getAllStaff ($live) {
            // Create SQL statement
            $sql = sprintf("SELECT * FROM staff WHERE live = '%s';",
                    $live);
            // Trace the query in the NetConnection debugger
            //NetDebug::trace($sql);
            // Run query on database
            $result = mysql_query($sql);
            
            $return = Array();
while($row=mysql_fetch_object($result)) {
                $row->last_updated = $this->datetime_mysql_to_mysoup($row->last_updated);
                array_push($return, $row);
            }
            return $return;         
    }

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: new to php - please help

Post by califdon »

You can pass multiple arguments to a function. Just separate them with a comma:

Code: Select all

function getAllStaff ($live, $tblname) {
unkempt
Forum Newbie
Posts: 6
Joined: Tue Mar 25, 2008 5:20 pm

Re: new to php - please help

Post by unkempt »

Thanks but how do i write this line so staff is replaced by $tblname

Code: Select all

$sql = sprintf("SELECT * FROM staff WHERE live = '%s';",
                    $live);
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: new to php - please help

Post by califdon »

unkempt wrote:Thanks but how do i write this line so staff is replaced by $tblname

Code: Select all

$sql = sprintf("SELECT * FROM staff WHERE live = '%s';",
                    $live);
Just replace "staff" with "$tblname".
Post Reply