lunac Posted April 6, 2007 Share Posted April 6, 2007 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? Link to comment https://forums.phpfreaks.com/topic/45889-is-the-possible-call-function-name-from-given-string/ Share on other sites More sharing options...
Jove Posted April 6, 2007 Share Posted April 6, 2007 look at this function: call_user_func() Link to comment https://forums.phpfreaks.com/topic/45889-is-the-possible-call-function-name-from-given-string/#findComment-222924 Share on other sites More sharing options...
lunac Posted April 6, 2007 Author Share Posted April 6, 2007 Ahh yes. Thanks. Link to comment https://forums.phpfreaks.com/topic/45889-is-the-possible-call-function-name-from-given-string/#findComment-223048 Share on other sites More sharing options...
lunac Posted April 6, 2007 Author Share Posted April 6, 2007 interesting... I just saw I had a typo too. It does work as I wrote it (typo fixed) -- but I don't know if that is proper coding. So I'll stick with the call_user_func(). Thanks again. Link to comment https://forums.phpfreaks.com/topic/45889-is-the-possible-call-function-name-from-given-string/#findComment-223066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.