Jump to content

is the possible -- call function name from given string


lunac

Recommended Posts

I'm trying to condense some of my code. I have some very similar functions that I want to make into 1 main function. Basically what it does is query the db then spit out a list of content which is formatted by another function called in the where loop:

 

ex:

function list_instructor_widget(){
// list of instructor_widget()
global $_tables;
$l = "";
$q = mysqlSelect($_tables['cminstructors'], 'id', "ORDER BY instructor ASC");
while($i = @mysql_fetch_assoc($q)){
	$l .= instructor_widget($i['id']);
}
return $l;
}

 

Some have more complicated queries, but the thought is that I can pass the query into the function. The only problem is how to change the inner function? I tried this, but it didn't work:

 

function list_widget($table, $queryitem, $widget, $conditions=""){
// creates a list out of individual widgets
global $_tables;
$l = "";
$q = mysqlSelect$table, $queryitem, $conditions);
while($i = @mysql_fetch_assoc($q)){
	$l .= $widget($queryitem);
}
return $l;
}
echo list_widget($_tables['cminstructors'], "id", "instructor_widget", "ORDER BY instructor ASC");

 

Any ideas? Is this even doable?

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.