#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    Hi all, thanks for the rapid help with my last problem. which was passing variables to a popup window, works like a charm now. But I have however run into another problem. And that is as follows. If an item is selected from a list that is drawn from the database. The full info on that item is to be shown.

    Now, one of the entries for that item/person is skills. There are 35 different skills in the database. And they can be either untrained(0), trained(1) or specialized(2).

    In the page displaying this, I have this statement.

    <?php $state=2;
    $hupp=26;
    for ($i=1; $i<=35; $i++) {
    check_skill_state($i, $state, $hupp);
    $hupp++;
    }
    ?>

    The function check_skill_state is defined in an include file and looks like this. The $template_array[] is all the data that has been drawn from the database table:

    function check_skill_state($count, $state, $select) {
    if ($template_array[$select] == $state) {
    print $skill[$count];
    }
    }

    $skill is an array that i defined like this:

    $skills = array("None", "Alchemy", "Appraise Armor", "Appraise Item",
    "Appraise Magic Item", "Appraise Weapon", "Arcane Lore",
    "Assess Creature", "Assess Person", "Axe", "Bow",
    "Cooking", "Creature Enchantment", "Crossbow", "Dagger",
    "Deception", "Fletching", "Healing", "Item Enchantment",
    "Jump", "Leadership", "Life Magic", "Lockpick", "Loyalty",
    "Mace", "Magic Defense", "Mana Conversion", "Melee Defense",
    "Missile Defense", "Run", "Spear", "Staff","Sword",
    "Thrown Weapons", "Unarmed Combat", "War Magic" );

    The problem is that the if statement never registers a "hit" ... even if I know that the record is the same as the value in $state.

    Do I make any sense at all?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    109
    Rep Power
    14
    Try this statement so you can see if the array contains the value you think it coontains, because it's possible that the array isn't defined correctly. Maybe you must pass it trough the parameters-list!

    Listing:
    function check_skill_state($count, $state, $select) {
    print $template_array[$select];
    if ($template_array[$select] == $state) {
    print $skill[$count];
    }
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    Trying this it correctly displays the values that has been entered into the database.

    So something is weird with the if-statement it seems. It never becomes true, even tho the value in the it is the same as it is for $state
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    $skills = array("None", "Alchemy", "Appraise Armor", "Appraise Item",
    "Appraise Magic Item", "Appraise Weapon", "Arcane Lore",
    "Assess Creature", "Assess Person", "Axe", "Bow",
    "Cooking", "Creature Enchantment", "Crossbow", "Dagger",
    "Deception", "Fletching", "Healing", "Item Enchantment",
    "Jump", "Leadership", "Life Magic", "Lockpick", "Loyalty",
    "Mace", "Magic Defense", "Mana Conversion", "Melee Defense",
    "Missile Defense", "Run", "Spear", "Staff","Sword",
    "Thrown Weapons", "Unarmed Combat", "War Magic" );


    remove double quotes from this array and see..


    $skills = array(None,Alchemy,Appraise Armor,Appraise Item,Appraise Magic Item,Appraise Weapon,Arcane Lore,
    Assess Creature,Assess Person, Axe, Bow,
    Cooking, Creature Enchantment, Crossbow, Dagger,
    Deception, Fletching, Healing, Item Enchantment,
    Jump, Leadership,Life Magic, Lockpick, Loyalty,
    Mace, Magic Defense, Mana Conversion, Melee Defense,
    Missile Defense, Run, Spear, Staff,Sword,
    Thrown Weapons, Unarmed Combat, War Magic );


    Also you can check it out wether the "if statement" is working or not.just print some message inside and see ,it is going inside the condition statement..

    if ($template_array[$select] == "$state") {
    print "it is workingn";
    //print $skill[$count];
    }


    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."


    [This message has been edited by Shiju Rajan (edited June 21, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    Well, it does fall thru the if statement. It registered the correct number of hits, but if I remove the double quotes, I get this message upon trying to load the page:

    Parse error: parse error, expecting `')'' in ./lib/squash.inc on line 751

    The array definition now looks like this:

    $skills = array(None, Alchemy, Appraise Armor, Appraise Item,
    Appraise Magic Item, Appraise Weapon, Arcane Lore,
    Assess Creature, Assess Person, Axe, Bow,
    Cooking, Creature Enchantment, Crossbow, Dagger,
    Deception, Fletching, Healing, Item Enchantment,
    Jump, Leadership, Life Magic, Lockpick, Loyalty,
    Mace, Magic Defense, Mana Conversion, Melee Defense,
    Missile Defense, Run, Spear, Staff, Sword,
    Thrown Weapons, Unarmed Combat, War Magic );


  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    109
    Rep Power
    14
    Another possibility is to put the array-values in single-quotes like:

    $skills = array('None','Alchemy', ... 'War Magic');

    Good luck
  12. #7
  13. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    The quotes suggestions are misplaced. The array() function has to have quotes and it makes no difference if it's single or double (unless you are assigning a value that contains one or the other).

    The problem I see with the code is the function itself. You refer to two different arrays ($template_array and $skill) that are not passed to the function. I assume you declared these as GLOBAL someplace???

    Also you refer to the array as $skill in the function, but in your assignment as $skills

  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    The $skill vs. $skills thing was a typo

    It refers to it by the correct name in the code.

    How do I declare it global?

    I tried putting global $skills; on the first line of the function, but that doesnt seem to help.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep Power
    0
    Never mind, it DID work with global $skills, problem was that I had commented out the array definition due to the parse error I got without the quotation marks, now it works... Thanks heaps guys

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. 2d array passed to a function
    By capaci in forum C Programming
    Replies: 1
    Last Post: February 13th, 2004, 09:54 PM
  3. array cannot be used as a function error:
    By helz in forum C Programming
    Replies: 7
    Last Post: January 20th, 2004, 11:21 AM
  4. Array function failing query
    By TuxLives in forum PHP Development
    Replies: 4
    Last Post: January 15th, 2004, 08:17 PM
  5. Passing array to function return problem
    By TuxLives in forum PHP Development
    Replies: 2
    Last Post: January 15th, 2004, 09:49 AM

IMN logo majestic logo threadwatch logo seochat tools logo