Jump to content

Newbie passing arguments - please help


unkempt

Recommended Posts

ok so im passing arguments to a function i.e.

[pre]function getAllStaff ($live, $tblname) {[/pre]

 

but how do i get $tblname argument to replace "staff" (the table) in the following code:

 

[pre]$sql = sprintf("SELECT * FROM staff WHERE live = '%s';",

                    $live);[/pre]

 

Hope you can help

Link to comment
https://forums.phpfreaks.com/topic/97948-newbie-passing-arguments-please-help/
Share on other sites

why you want to use like this

change the below code

$sql = sprintf("SELECT * FROM staff WHERE live = '%s';",
                    $live);

 

TO

 

$sql = "SELECT * FROM ".$tblname."  WHERE live ='".$live."'";

 

OR

$sql = "SELECT * FROM $tblname  WHERE live ='$live'";

 

OR

$sql = 'SELECT * FROM '.$tblname.'  WHERE live ='.$live;

Thanks but that didn't seem to work - here is my function - does this look correct:

 

[pre]function getAllWorks ($live, $tblname) {

// Create SQL statement

$sql = sprintf("SELECT * FROM %s WHERE live = '%s';", $live, $tblname);

// 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;

}

[/pre]

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.