Jump to content

djpurpose

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

djpurpose's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok I think I'm really close . The code should look something like this but this doesn't work. I haven't gotten the file stuff to work at all and I'm not sure why. Check the cose out and let me know what's wrong. The concatenation is the only thing I can confirm as working. /******************************************************************* Cycles through user names "user_1" through "user_50" then resets and starts over. The current number is stored in a text file. *******************************************************************/ $user_file_name = 'current_user.txt'; //File name if(($current_user_file = fopen($user_file_name, 'r')) ===FLASE){ //Open file to read the current user number die('Failed to open file for reading!');} $current_user_number = fgets($current_user_file, 2); //reads the user number from the file $database_user_string= "user_" . $current_user_number; //add the text "user_" and number (ie "user_3) fclose($current_user_file); //close the file if(($current_user_file = fopen($user_file_name, 'w')) ===FLASE){ //Open file to write the current user number die('Failed to open file for writing!');} $current_user_number++; //incement $current_user_number by 1 if($current_user_number > 49) $current_user_number = 0; //reset $current_user_number if it gets to 50 else fwrite($current_user_file, $current_user_number); //Write the over the new $current_user_number fclose($current_user_file); //close the file
  2. Thank you very much for your reply. It seems like the serialize would be quicker. Do you have an example of how to code that? I read up on serialize and it's pretty confusing and all the examples are overly complex.
  3. I'm surprised I haven't gotten a response. In c++ I know this would take less than 10 lines of code. At the very least how would I concatenate a string with a int formated to 2 digits. in ANSI C it would look like this: char s[6]; //create an empty string int current_user_number = 3 //create int and initialize it to 3 for illustration sprintf(s,"user_%02d",current_user_number); //add the text "user_" and the int with a leading zero if it's less than 10 After the above code s = "user_03"
  4. I guess I should have explained this a little bit better. The "user" is the database user that is used to gain access to the database. So every time a connection needs to be made to the database I want to use a different user. The only thing that needs to be in the database is the increment variable, all the rest of the stuff can happen the the php code. I'll try to comment my sudocode so it's easier to understand and rename my variables so they are easier to read. Please excuse my sudocode. I'm a c++ coder in case the code looks weird.... /* Variable descriptions $number_of_users //keeps hold the total number of user names I'm going to create, Lets make it 50 for example's sake $current_user_number//increment variable used to get the last part of the user name (ie. to get the text "user_01" I would concatenate "user_" with $current_user_number (formated with a leading 0 for numbers less than 10 ie: 01, 02...10) */ //Variable declaration static int $number_of_users=50; //total number of users (hard coded) string $database_user; //used to hold the text of the user name (ie: "user_01") if $current_user_number does not exist in database then create it and initialize to 0 //will happen only once $database_user = the text "user" + $user_number //concatenated if ($current_user_number < $number_of_users) //if current user is less than 50 $current_user_number++; //increment to the next user for next time else $user_number = 0; //Once we hit the 50th user we start back at 0
  5. Below is some code I use for an osCommerce from the "configure.php" file store to rotate the database user so I don't exceed my very low "max_questions" limit. Right now it's using random to cycle between what database user is used to connect. I want to change it from being random to being sequential since the random causes un-even distribution of what user gets used. $database_user_array[] = "user_01"; $database_user_array[] = "user_02"; $database_user_array[] = "user_03"; $database_user_array[] = "user_04"; $database_user = $database_user_array[ rand( 0, ( sizeof($database_user_array) -1 ) ) ]; Go easy on me as I'm a newbie. I'm just not sure how this thing works. If an increment variable is added will the value be kept track of? I'm assuming I need something like this sudo code (be gentle). $N=number of database users if $user_number variable does not exist in database then create it and initialize to 0 database user = the text "user" + $user_number (with leading 0 if less than 10) if variable is less than $N then $user_number++ else $user_number = 0
×
×
  • 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.