whatshakin Posted October 12, 2009 Share Posted October 12, 2009 I have this fuction which is inside a class: public static function generateEmbedCode($callId, $width="425", $height="320", $swfobjectPath="SDK/js/swfobject.js", $inviteButton="1", $guestList="1", $observerMode="0", $displayName="$nick") { Blah Blah } What i need to do is grab some info and place it into a variable for $displayName="$nick" using: $memberid = (int)$_COOKIE['memberID']; $sQuery = "SELECT * FROM `Profiles` WHERE `ID` = '$memberid'"; $result = db_res($sQuery); while ( $p_arr = mysql_fetch_array( $result ) ) { //get profile data $nick = $p_arr['NickName']; } But I can't get it to work, my question is how can I get a variable to work inside the params of a function?? i hope this makes sense. Thanks Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/ Share on other sites More sharing options...
trq Posted October 12, 2009 Share Posted October 12, 2009 You cannot use a variable as a default for an optional argument, which is what $displayName="$nick" within your argument list does. You'll need to parse your $nick variable to the function explicitly. Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935219 Share on other sites More sharing options...
whatshakin Posted October 12, 2009 Author Share Posted October 12, 2009 Thanks, Here's the whole function: public static function generateEmbedCode($callId, $width="425", $height="320", $swfobjectPath="SDK/js/swfobject.js", $inviteButton="1", $guestList="1", $observerMode="0", $displayName="$nick") { $bodyCode = "<script type=\"text/javascript\" src=\"$swfobjectPath\"></script>\n". "<script type=\"text/javascript\">\n". "\tvar flashvars = {};\n". "\tflashvars.inviteButton = \"$inviteButton\";\n". "\tflashvars.guestList = \"$guestList\";\n". "\tflashvars.observerMode = \"$observerMode\";\n". "\tflashvars.displayName = \"$displayName\";\n". "\tvar params = {};\n". "\tparams.allowfullscreen = \"true\";\n". "\tparams.allowscriptaccess = \"always\";\n". "\tvar attributes = {};\n". "\tattributes.id = \"tbx_call\";\n". "\tswfobject.embedSWF(\"".API_Config::API_SERVER.TokBoxApi::$API_SERVER_CALL_WIDGET.$callId."\", \"widgetDiv\", \"$width\", \"$height\", \"9.0.115\", false, flashvars, params, attributes);\n". "</script>\n". "<div id=\"widgetDiv\">\n". "\t<a href=\"http://www.adobe.com/go/getflashplayer\">\n". "\t\t<img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" />\n". "\t</a>\n". "</div>\n"; return $bodyCode; } So would I have to add something inside this function to get it to display properly? Sorry I just really don't know Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935250 Share on other sites More sharing options...
trq Posted October 12, 2009 Share Posted October 12, 2009 You need to pass a displayName as the last argument to your function. Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935253 Share on other sites More sharing options...
whatshakin Posted October 12, 2009 Author Share Posted October 12, 2009 Okay, I don't know what pass displayName as an argument means. If you could please show me I would greatly appreciate it. Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935258 Share on other sites More sharing options...
trq Posted October 12, 2009 Share Posted October 12, 2009 Function get called with arguments. eg; foo('hello'); This calls the function foo and passes it the string hello. When you call your function generateEmbedCode(), the last argument it requires is your display name. Trying to set a default value as a variable within your function definition as you have done will not work. Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935268 Share on other sites More sharing options...
whatshakin Posted October 12, 2009 Author Share Posted October 12, 2009 ok, i see now. So how can i explicitly build this into the function? Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935457 Share on other sites More sharing options...
whatshakin Posted October 12, 2009 Author Share Posted October 12, 2009 Ok all I had to do was define the $displayName within the main function and it shows up fine. Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935469 Share on other sites More sharing options...
trq Posted October 12, 2009 Share Posted October 12, 2009 Hardly any point in using a function then is there? Link to comment https://forums.phpfreaks.com/topic/177376-solved-getting-a-variable-to-work-in-function-params/#findComment-935740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.