Database difficulty....

EnverexEnverex Worcester, UK Icrontian
edited December 2003 in Internet & Media
Basically I am trying to add some more fields to my games section, specifically being a language field, so that I can use flags for display on what language(s) the game is in.

But I cant think what would be the best way to go about it.

First I though using IDs, like 1 for English, 2 for French, etc, but a game may have more than 1 language, so I would end up doing IDs for every possible combination.

Next, I though of using a field for each language and just putting a "y" in that record if it supported that language, as then I can just check at coding level what is ticked and add the flag for each, but that is messy if I want to add more.

Does anyone have an idea of how to do this exactly....

When I put a game in, in the box, if I could enter say, en for english, but if it had more than one language, enter "eng ger". Thats easy enough, but then it comes down to calling it out. What way could I check what is in there, i.e. some sort of regex thing to see what languages are in the box, and then just using "ifs" display the right flags.

Basically its the "working out what is in the box when there are mulitple languages" is the bit I need to work out.

Unless anyone has a better idea on how to do it...

Cheers,
EX

Comments

  • Josh-Josh- Royal Oak, MI
    edited December 2003
    What kind of database? Is this web based? mySQL?
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    MySQL and the results are being pulled through PHP.
  • Josh-Josh- Royal Oak, MI
    edited December 2003
    Just make multiple tables within the database itself and you should be able to more easily manage it that way. If you give me a day or 2 I'll write something up for you to use.
  • Straight_ManStraight_Man Geeky, in my own way Naples, FL Icrontian
    edited December 2003
    Right, and can you pull from a new table and integrate it into the DB???

    And maybe use 2 letter Linux international language codes??? Those would cover the major things. EN for English, DE for German (Deutsch), SE for Swedish, and like that.

    Table key could be game ID or name, than 5-6 fields for language codes. No reason PHP cannot pull reports from multiple tables, and IIRC you should be able to pull a table into a DB structure and use SQL calls with an output join (to pull in game name if you use game ID as key, or vice versa) to pull direct SQL query responses that would get you:

    Game ID, Game Name, Lang1, Lang2, Lang3, lang4, Lang5, Lang6EOL

    Output to a temp table as file in CSEOL delimited format.

    And then format as a printed report in PHP, maybe tabs for every space, hard return for every EOL given and used as record break. That is the quick way, and you might be able to merge into DB with a join with SQL also. join then becomes main table unless you want a realtional setup, then leave separate and use queries to make an implicit join of what is wanted on output\result, which probably could be directly to a Printer pipe if wanted, or piped to lpr (which will use default printer queue if no printer name specified and is how I print man pages, ie:

    man lpr > lpr.txt | lpr

    OR

    man lpr > lpr.txt
    cat lpr.txt | lpr

    Use end '| lpr' if you can get pipes out of MySQL.

    If you do not like that idea, let me know, or Josh-

    John.
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    -Josh: I don't need you to make a database, I already have an entirely working sturcture for the system, I just need the best way of specifying a language.

    Ageek: That is all completely unecessary.

    You all seem to be misunderstanding. I have a working database with full structure and all the information in it, I am just trying to think of the best way to store a certain record.

    This is the actual system - http://atomnet.co.uk/amiga/?p=engine

    What I am going to do is add a field that just contains something like "EN" or "EN FR GE". But the thing is, I could do what Ageek said "Game ID, Game Name, Lang1, Lang2, Lang3, lang4, Lang5" But I don't want to have say 8 fields (one for each language) when most of the time, most of them are not going to be used, so what I wanted to do was use one field and put it all in there i.e. "EN GE FR IT" and then break that down. All I need is the code at PHP level to break it down into some sort of boolean system, so that if the record contains "IT" then $lngIT will be true. So I could just do a few if statements to display the correct flag depending on the fields contents.

    So basically, I need some sort of code that checks if the record contains "IT" or "EN" or "FR" etc and sets a variable for each one to true, NOTHING MORE (as you all seem to be going a little over the top) I can do everything else myself, it is just this that I need to do as I am not very prefitient in string detection coding.

    Cheers,
    EX
  • Josh-Josh- Royal Oak, MI
    edited December 2003
    <form>
    <select name="sortby">
    <option value="EN">EN
    <option value="FR">FR
    <option value="GR">GR
    <option value="IT">IT
    </select>
    </form>
    Like that..?
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    Nooooo....

    Nevermind, I'll try to figure it out myself as I don't seem to be able to explain it well enough for anyone to work out what I am talking about.
  • a2jfreaka2jfreak Houston, TX Member
    edited December 2003
    SELECT * FROM Table WHERE Lang LIKE "%EN%"
    ???
    (I think that's the SQL for it)
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    Right, I have managed to do it anyway.

    The initial question, was, how is the best way to store, in a single record, multiple values, and then, when you call them back up, split them up.

    This is how the result looks (just look at this page, I haven't added languages to all the rest yet) - http://atomnet.co.uk/amiga/?p=engine&letter=

    In the end I decided to just store all the values in the same field for each record and use this code to detect what is stored in the record itself -

    [PHP]
    $lang1 = "";
    $lang2 = "";
    $lang3 = "";
    $lang4 = "";
    $lang5 = "";

    // Check what languages are supported
    if(strpos ($languages, "en") !== FALSE)
    {$lang1 = '<img src="/ss/sflags/uk.gif">';};

    if(strpos ($languages, "de") !== FALSE)
    {$lang2 = '<img src="/ss/sflags/de.gif">';};

    if(strpos ($languages, "fr") !== FALSE)
    {$lang3 = '<img src="/ss/sflags/fr.gif">';};

    if(strpos ($languages, "it") !== FALSE)
    {$lang4 = '<img src="/ss/sflags/it.gif">';};

    if(strpos ($languages, "es") !== FALSE)
    {$lang4 = '<img src="/ss/sflags/es.gif">';};
    [/PHP]

    The code for the entire page is here - http://atomnet.co.uk/amiga/engine.phps

    And it works how I want. Cheers anyway.
  • a2jfreaka2jfreak Houston, TX Member
    edited December 2003
    You could go about it like you would for the rwx info in a Unix FS.

    EN = 1
    DE = 2
    FR = 4
    IT = 8
    ES = 16

    All langs = 31
    EN + DE = 3
    EN + FR = 5
    DE + ES = 18
    You get the idea.

    But since you have it working, no big deal.
    Whatever floats your boat.
  • Josh-Josh- Royal Oak, MI
    edited December 2003
    Enverex wrote:
    Nooooo....

    Nevermind, I'll try to figure it out myself as I don't seem to be able to explain it well enough for anyone to work out what I am talking about.

    Dude..no need to be a jack ass about it. I offered to write you a script for the full thing, since you obviously aren't explaining it well enough and I am having trouble understanding what your asking for. Maybe you could explain better and I can help you.
    -Josh: I don't need you to make a database, I already have an entirely working sturcture for the system, I just need the best way of specifying a language.

    Ageek: That is all completely unecessary.
    We at least tried to help dude; it isn't our fault if we don't understand or misunderstand in your words what your talking bout, it doesn't make us stupid.
    :hrm::-/ :shakehead
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    Josh- wrote:
    Dude..no need to be a jack ass about it. I offered to write you a script for the full thing, since you obviously aren't explaining it well enough and I am having trouble understanding what your asking for. Maybe you could explain better and I can help you.

    Excuse me? I SAID that I couldn't explain it well enough, how is that ME being a Jackass? I said that I could not explain it well enough, how would you LIKE me to phrase it? I simply said that there was no point going through all the effort of doing other things which weren't what I needed, maybe I should have just let you carry on?

    a2jfreak: I see what you mean, but I am not sure how that would work when you are trying to work out what the value is made up of, and it seems a lot more effort. Cheers for the idea though.
  • Park_7677Park_7677 Missouri Member
    edited December 2003
    How I would do it, is just have a set number of characters represent a language.

    EN = English
    FR = French
    etc.. and within the database field just lump them together. Split them apart in the PHP to an array, loop it and add the image HTML to the end of a string.

    You could do $lang# = image HTML simple enough. If you want, I'll write the code.

    [PHP]// Fake str for testing
    $STRING_FROM_DATABASE = "ENDEFR";

    $lang_str = trim(chunk_split($STRING_FROM_DATABASE,2," "));
    $lang_ary = explode(" ", $lang_str);
    $pic_str = "";

    foreach ($lang_ary as $key=>$lang) {
    $pic_str .= '<img src="/ss/sflags/'. $lang .'.gif">';
    }

    echo $pic_str;[/PHP]
  • EnverexEnverex Worcester, UK Icrontian
    edited December 2003
    Cheers park. That is what I was looking for, but I may as well just stick with my system for now as it's already in place, but I will keep that in mind for future work.
Sign In or Register to comment.