0

I am not herein asking for anyone to do the work for me, i just need a point in the right direction, since i seem to keep backtracking. =) So my problem is this:

On the website, i have 4 donation perks "boxes" (a list of perks someone will get as a thank you for donating). Now, i am putting an input form on the top, where a person could type in their name, and if userx has already donated before, but want to check what better perks he could get, he puts in his name, and then it shows only like say boxes 3 and 4.

Boxes 1-4 = VIP, SuperVIP, EliteVIP, EliteModerator.

The form should check against a single file containing all the names/perks-packages, and its already nicely formatted like this:

hvv7:
 subgroups: []
 permissions: []
 group: SuperVip
TEAR_GAS_TEDDY:
 subgroups: []
 permissions: []
 group: EliteVip
KMoore11:
 subgroups: []
 permissions: []
 group: SuperVip
EanEuropean:
 subgroups: []
 permissions: []
 group: Moderator
powerwind:
 subgroups: []
 permissions: []
 group: Vip

Again, i really just need a push in the right direction, but any help/answers will be much appreciated. Reason i am here today is because, i know of a few ways to check the word already, but what baffles me is checking the word, and then getting the info 3 lines down, having that return and then changing some div's visibily (to hide the ones userx already has)

EDIT: Hmm, still researching, i wonder if it would be easier to just get the name/group into mysql, and then having the script just read that instead lol.

4
  • Is it necessary for you to store your data in a flat, human readable file like that, so you have to manually parse it every time you want to read/change some data? If you have no access to/desire for a DB you might be interested in serialize(). As far as updating the page goes - do you want to do this with AJAX or by reloading the page? Commented Aug 16, 2011 at 14:09
  • @DaveRandom I wish i was able to change the way it's stored. The game server saves the file like this, and then uses it like say "userx has vip, loads certain commands/perks". Also, i was thinking about going ajax, that way people with maybe slower connects dont have to reload, and the form should still keep the information. Commented Aug 16, 2011 at 14:16
  • There's a lot of code that needs writing here, but basically what you need are: a PHP procedure to parse the file and read certain data, and a JS procedure to pass the username back to the server and fetch the current level, then update the display on your user's page. I can't really give you much of a push without actually writing some of it for you... Commented Aug 16, 2011 at 14:25
  • Its fine then, just seeking out tips. :) Commented Aug 16, 2011 at 14:30

5 Answers 5

1

Use regex from an offset of the username to grab the first group below that username. Like so:

$data = file_get_contents("file.txt");
$username = "hvv7"; // Example username
$offset = stripos($data, $username);
$group = "";    

if(preg_match("/group:([ A-Z0-9]+)/i", $data, $matches, PREG_OFFSET_CAPTURE, $offset))
{
    $group = $matches[1][0];
}

echo $group; // Something like Vip
Sign up to request clarification or add additional context in comments.

Comments

0
$content = get_file_contents('file.txt');
$content = explode("\n",$content);//split by line...
$group = $content[3];// returns "group: SuperVip"

// the 3 is the indexed number. or something similar in those lines... not sure if explode would work but hey give it a go :)

Comments

0

The clue is in the name - DATA base.

PHP does not have the file locking locking semantics required for managing concurrent access to flat file data. And that's before you start considering the complications of seeking within the file and parsing its structure.

Use a database.

Comments

0

use the other answers in order to fetch the type of moderator. in terms of the jquery on the page, i would put all the names in an array in the order of hierarchy so

var groups = ["Vip","Moderator","SuperVip","EliteVip","EliteModerator"]; 

Then say your variable is

var usergroup = "whatevertheuserGroupYouGetFromPHP";

var index = groups.indexOf(usergroup);

var tempGroups = groups;

tempGroups.splice(0,index);

$.each(tempGroups,function(index,value) {
      $("#" + value).show();
});

and make all ur boxes CSS be initially have display:none;

and also give them each the ID that matches the group names. that should work

Comments

0

You can use JSON format for your file. Using json_encode and json_decode functions you can easily read, modify and write your data structure.

For example you can have an array like this:

$data = array(
    "hvy7" => array(
        "subgroups" => array(),
        "permissions" => array(),
        "group" => "SuperVip"
    ),
    "TEAR_GAS_TEDDY" => array(
        "subgroups" => array(),
        "permissions" => array(),
        "group" => "EliteVIP"
    )
);

Of course this is not a good example of data structure. But i think you'll get the point. You can access them as normal php object. Than you can export as JSON format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.