Here is what I want to do, I am trying to design a fairly complicated mysql database, and I would like to hear some ideas from the community of how to go about this particular funtion I need php and mysql to do.

Areas of land will have their own unique number associated with it. What I want to do is in mysql, define the individual lands attributes, and in it define the neighboring lands for use in the php script later to send spies or go to war. As they can only do this to neighboring lands.

It's pretty much a primitive map system.

The only thing is, I am not sure how to go about it.

If you could, please give me an example of the mysql syntax you would use and how you might parse that in the php so that they are turned into variables to be used for output to the user of what options are available to them. Also, I hope going about it this way would ignore all other lands except the defined neighboring lands. I figure this might cut down on resources on the server.

I could be way off, or overthinking it. That happens alot especially when your as loopy as I am right now (coding for a solid week now)

Thanx!

    Just an idea...

    If you know the neighboors, why not group them with a second attribute named group_id?

    So you could get all stuff via

    $resource = mysql_query("SELECT land, group_id AS gid, id FROM areas GROUP BY group_id ORDER BY id DESC");
    

    And parse the groups into the array $group like this

    //store our groups here
    $group = array();
    
    //last group id
    $last_gid = -1;
    
    //let's go...
    while($result = mysql_fetch_array($resource))
    {
    //are we in the same group as the last one?
    if($last_gid != $result['id'])
    {
    //ok then let's add to the group
    $group[ $result['gid'] ][] = array("group_id" => $result['gid'],
    "area_id" => $result['id']);
    }
    
    //set last gid
    $last_gid = $result['gid'];
    
    }
    
    //free memory
    @mysql_free_result();

    And know, tadaaa, you have an array with your group_id as the index, and all areas related to this group are in the array with numeric index.

    So via $group[0]['your_attrib'] you are able to access the vars of your area in their relating group one. Don't forget that the first index is your group_id.

    Hope you'll like my idea

    😃

      Thanks for the response David. Deffinatly got me thinking about some possibilities for future itterations of this project. I think i'll need more experiance though with things (the AS statement, threw me for instance lol)

      The way I was hoping to do it, though was to physically define the neighboring land under that particular lands attributes in mysql as it would be static to the image map that I will be drawing. So for instance the land I own has the uniqe id number of 5, because of the shape of this land (shape and size wont have corelation to actuall land mass in the game yet. Just how many other lands you are next to) it is next to 6 other lands. These lands have the numbers 6, 14, 27, 12, 1, 2 Trying to keep things simple, i'd like to have it individually defined within each land entry under the 'province' table. Then have the script be able to pull that information whenever diplomacy, spy, or war type interactions are done.

      The main problem I run into is probably a novice problem. I am not sure what sort of mysql database entry I should use to record this information, then what I should do in the script to call it up so that the rest of the script can tell the user if they are allowed to go to war with a particular land or not, for instance.

      What do you think?

      Thanks again!

        Hmmm, then I would prefer to store the neighboors in an serialized array to your 'province' table - if you are not already doing it this way. (?)

        How much's the data we're talking about? Maybe you'll post some infos on your database layout 😉

        Well, If you're changing the relating informations frequently, you'll get performance lacks at some point.

        The other point is, that this way you run into redundancy. But with my "group solution" you just need to change group id's if some land "moves" ore something.

        You could also add an table with more informations relating to the groups...

        Very hard to decide what's "the" right way :rolleyes:

          The neighboring lands will stay static to the actuall drawn map that I create. So once they are defined, they wont be changed. There will be difference maps for different games that are in progress. As far as I can tell it's just a matter of somehow putting in a list of numbers (seperated by commas maybe?) that the script can look at and tell the user what he/she can and cannot do.

          Another note, as the user plays and takes ownership of other provinces, they must move to that new province in order to position themselves for attack that new provinces neighboring land. Or order a prince that you assigned to that land to attack.

            Would this work:

            neighbors text NOT NULL

            and in the text put in entries of neighboring land ids like this:
            24,2,5,9

            how can I get php to parse that information if that would work?

              You can extract the numbers using
              $neighbours = explode( ',' , "9,24,3,14,5,26" );

              This gives you an array with 6 elements.

              Halfabee

                oh ya! expload. ok.

                So that means that putting in an if statement like

                if ( $landid == $neighbours ) //canint is for can interact
                {
                     $interact = 1
                else
                     $interact = 0
                }
                

                probably bad coding right there, but just a general idea.

                Am I going in the right direction?

                Thanks guys.

                  While $neighboors is an array, you have to...

                  ...use this method 😃

                  if ( in_array($landid, $neighbours) ) //canint is for can interact
                  {
                       $interact = 1
                  else
                       $interact = 0
                  }
                    Write a Reply...