Jump to content

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]

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.