Page 1 of 1

new to php - please help

Posted: Tue Mar 25, 2008 5:26 pm
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.

Re: new to php - please help

Posted: Tue Mar 25, 2008 9:38 pm
by califdon
You can pass multiple arguments to a function. Just separate them with a comma:

Code: Select all

function getAllStaff ($live, $tblname) {

Re: new to php - please help

Posted: Wed Mar 26, 2008 5:24 am
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);

Re: new to php - please help

Posted: Wed Mar 26, 2008 1:54 pm
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".