Jump to content

NeoMarine

Members
  • Posts

    73
  • Joined

  • Last visited

    Never

Everything posted by NeoMarine

  1. Wow I didn't know of that array version of the function. Many thanks! It works
  2. Anyway, this would be fine but its not what I'm referring to. I haven't got a problem telling how many parameters are passed into the array. I'm just trying to call my function which is stored in a database field in the structure: functionName# var1# var2# etc... and I then explode this string by the "#" and then I know how many vars/parameters there are.. then I want to call it using call_user_func() - but to do so without using eval to "assemble" the function string to be executed
  3. Ok let me explain a bit further... In my database I store the function name and its parameters (which can be a variable amount of parameters). I then do: sizeof($Parameters) - and know from this how many parameters to put into call_user_func() - the only problem is I don't want to have to do "switch" statement based on the number of parameters... I'd like to do, if possible: call_user_func($functionName, $field1 (if field 1 exists), $field2 (if field 2 exists))
  4. I don't want to do it that way as I mentioned. No using func_get_args - for me to do that I'd have to change my functions structures site-wide which, for me is a lot of functions.
  5. Hello, How to do this more efficiently, without using eval(); and without passing the parameters as an array into the function - I need to call the function in its usual structure: $functionName = "functionName"; $field1 = "firstFunctionParameterValue"; $field2 = "secondFunctionParameterValue"; $numberOfParameters = 2; switch ($numberOfParameters){ case "1": call_user_func($functionName, $field1); break; case "2": call_user_func($functionName, $field1, $field2); break; } So, based on "$numberOfParameters" I'd like to call_user_func() WITH that number of paramaters. Clues? Ideas? Thoughts?
  6. nevermind.. I found this code which does it: $strFromDB = "fcall1();"; eval("\$line = " . $strFromDB); echo $line;
  7. Note: If I try using: eval("echo $mysqlValue"); it only echo's the string of the variable and results in echoing to screen: "myfunction($param1value="1",$param2value="2",$param3value="3");"
  8. $mysqlValue='myfunction($param1value="1",$param2value="2",$param3value="3");'; eval("$mysqlValue"); This works fine... BUT, I want to do: $myfunctionResult = eval("$mysqlValue"); echo $myfunctionResult; ..and it doesn't work??
  9. Hello, In my database I have a field where I store a value such as "myfunction($param1value="1",$param2value="2",$param3value="3");" What I want to do, is to basically use that value and execute the function on a php page, like: $mysqlValue="myfunction($param1value="1",$param2value="2",$param3value="3");"; $mysqlValue(); // only with the parameter values and everything in otherwords, I want to get the following to execute: <?php myfunction($param1value="1",$param2value="2",$param3value="3"); ?> ANY IDEAS? Is this possible? I am aware of variable functions but that doesn't seem to support parameter values in the string(variable)-to-function.
  10. I'm curious, how can I basically set up something like: if (HTTP_HOST!="http://www.alloweddomain.com"){ die("You're using an illegal copy of this script."); } To help protect my scripts. I realize I would need to hide that section of code and even obfuscate it, which I probably can do, but I'm trying to make a "kill switch" for anyone attempting to pirate my scripts.
  11. I hold two statistics in my database, one for "Thumbs Up" and one for "Thumbs Down". Based on the ratio of Thumbs up/down, I want to display a message to the user such as: "You are generous" (mostly thumbs up) or "You are ungenerous" (mostly thumbs down). I have the following math done: $thumbsCombinedTotal=$thumbsUpCount+$thumbsDownCount; $thumbsUpPercentage=round(($thumbsUpCount/$thumbsCombinedTotal)*100,2); However, if the user has thumbs up = 1, and thumbs down = 0 - this will generate a value of 100% so I would say "you are extremely generous". But what I really would like to say is, "you are generous", because they have only voted on 1 thing altogether. Can you think of some more detailed math so I can determine a more accurate description of their "favor in the ratio" (ie. how generous they are actually being?) I need some kind of gradual scale in the math, which means, the more COMBINED thumbsup+thumbsdown they have, the more it will influence the severity of their generousity/ungenerousity. I hope I am clear enough. Thanks a lot to whoever can help me.
  12. sasa you rock, it works! I really appreciate this!
  13. Does anyone have any idea how? I really need to figure it out
  14. Thanks premiso, I had planned to use the database field as the fall-back idea. I just wasn't sure if it was possible to determine anothers session. The DB solution is the best option, I agree.
  15. How can I force a user to be logged out (clear their session)? If I typed: unset($_SESSION['user']); This would only log ME out. How can I log out someone else? I require this for the purpose of being able to change users "username" - which means they need to be force-logged out when I change it.
  16. Hey, I have a multidimensional array which is created already and I need to Sort it by the values inside. Although I have figured out how to do this normally, I cannot figure out how to do it through a recursive function so I dont need to keep creating the same code over and over inside of it just to create an additional loop. Here is my code: $newFileArray=array(); $levelSize0=sizeof($levelFileArray[0]); $levelSize1=sizeof($levelFileArray[1]); $levelSize2=sizeof($levelFileArray[2]); for ($iL0=0; $iL0!=$levelSize0; $iL0++){ $newFileArray[] = $levelFileArray[0][$iL0]; for ($iL1=0; $iL1!=$levelSize1; $iL1++){ if ($levelFileArray[0][$iL0]['ID']==$levelFileArray[1][$iL1]['RepliedToStartID']){ //Matching start id $newFileArray[] = $levelFileArray[1][$iL1]; # REPEAT POINT ("START POINT") for ($iL2=0; $iL2!=$levelSize2; $iL2++){ if ($levelFileArray[1][$iL1]['ID']==$levelFileArray[2][$iL2]['RepliedToStartID']){ //Matching start id $newFileArray[] = $levelFileArray[2][$iL2]; # REPEAT POINT 2 ("START POINT") // Normally I would keep adding code here to add another loop unset($levelFileArray[2][$iL2]); } } unset($levelFileArray[1][$iL1]); } } } $levelFileArray is my multidimensional array I wish to sort through the recursive function. However, since I need to add a new value to the $newFileArray, every time I return the array, it returns it as a "whole" instead of a single value so I cannot figure out how to go about what I'm doing about in a more "infinite" way?
  17. Its ok, I decided to leave this feature out of my project considering its a bit excessive for my needs at the moment - will look into solutions in future if needed. Thanks for your time.
  18. Ok so here is the structure of my table: ID - OwnersID - TheMessage - DateTimeAdded - UsersID - RepliedToStartID - RepliedToLevel What I'm trying to accomplish: I display a series of messages on the page, and I allow users to "reply" to a particular message. When someone replies to that message, I need it to be displayed "underneath" the message it was a reply to. How I store my data: I use the column RepliedToStartID as the "ID" of the row that the message is owned by, at the very base level. The RepliedToLevel tells me the "level" deep the message is at. So, if john (whos ID is 100) wrote a message and sarah replied to the message later on (whos ID is 105), on screen it should show johns message, followed by sarahs message - and sarahs RepliedToStartID = johns ID (100), and RepliedToLevel = 1. The query: The query therefore needs to "ORDER" the messages "BY" the DateAdded, and then if a previous rows ID = the next rows RepliedToStartID, that row should be placed after the previous row. One idea I had was to use multiple queries, which would be rather simple - but also taxing on the server - I dont want to slow things down. So, essentially I must create a query that selects the rows by their RepliedToStartID, as well as the DateAdded and RepliedToLevel - but in the ORDER of "Message (100)" and then "Message (105)" -- 105 being the message with RepliedToStartID of 100 and Message 100 being the previous message displayed.
  19. I tried, it doesn't work. The variable names are returned as index-numbers, eg: 0=Cool, 1=1234 I think that functions don't obtain the variable "name"... surely there is some work around though hmm
  20. I'm trying to loop through all the arguments passed into the function: foreach (get_func_arg() as $variableName => $variableValue){ $argumentsPassed .= $variableName."=".$variableValue.", "; } return $argumentsPassed; So, if I entered something like: $variable1="Cool"; $coolStuff="1234"; echo myFunction($variable1, $coolStuff); The output will be: $variable1=Cool, $coolStuff="1234" (or without the $'s) ANY IDEAS?? Is it even possible?? I need this because my variable names are required, and their could be any number of function arguments(variables) passed
  21. Wow, it worked! Thanks a bunch! one more Question though, what the heck is $$ (double $) for $$property, when I took that out it failed
  22. that's right, dynamically! but how? I tried a foreach loop with get_defined_vars but that doesn't seem to work
  23. Is it possible to convert $this -> variableName to $variableName? I want to somehow loop through all the variables in scope (get_defined_vars()) and have the variables set in as $variableName so I can then just type: echo $variableName instead of echo $this->$variableName thanks
×
×
  • 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.