Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts

    Matching sets in query

    So this is kind of tough to explain, bear with me. I want it to show how many sets you have if an item is identical multiple times. So default would be 1 Set. If an item matches twice, it would show 2 Sets.

    I am using mysql_fetch_array and mysql_num_rows for my queries. But how do I set it up to check all items for multiple matches?

    Like if I had a Long Sword, and there are two of them, It should show Long Sword (2 Sets). I have all the other coding finished, just need the sets completed.

    Here is my coding where I need to find a way to add it.

    PHP Code:
    $page .= '<p><table width="95%">';
            if (
    mysql_num_rows($weaponquery) == 0) {
              
    $page .= 'You have no weapons.<br />';
            }
            else {
            while (
    $wrow mysql_fetch_array($weaponquery)) {
            
    $page .= '<tr><td><b>Weapon Name</b></td><td><b>Min Level</b></td><td><b>Damage</b></td><td><b>Class</b></td><td><b>Upgrade</b></td><td><b>Action</b></td><td><b>Sets</b></td></tr>';
            
    $page .= "<tr><td>".$wrow['name']."</td><td>Lvl ".$wrow['requirement']."</td><td>+".$wrow['attribute']."</td><td>$weapon1</td><td>+".$wrow['bonusattack']."</td><td>EQUIP</td><td>1</td></tr>";
          }
     }
            
    $page .= '</table>'
    Last edited by myfayt; 08-26-2011 at 07:32 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    What do the tables look like that you are querying from? (I think this would work) Ever thought of a table like -weapons- and each unique weapon has an a weaponID. Then, in your user's inventory table, so to speak, you have just the weapon ids with a sets column. Each time a user, purchases or finds an item, you check to see if they have already have purchased one, if so then add how ever many they are purchasing or found to the intial set number. If not then, you add it to the user's inventory with the amount of sets they are purchasing or found. Using a join between the weapons table and the user's inventory table, you display the user's inventory.

    In theory, I think that would work O.o I could be wrong.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • Users who have thanked Chris Hick for this post:

    myfayt (08-26-2011)

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Here is the coding I am using. There is a name field which will would be the same name if they are alike. So we can use that to check for doubles.


    PHP Code:
     $weaponquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND type='1'"'smithcreate');
        
    $classweapon mysql_fetch_array($weaponquery);
        
        
    $armorquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND type='2'"'smithcreate');

        
        
    $shieldquery doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."' AND type='3'"'smithcreate'); 

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Actually I don't think it's possible because of the way the structure is setup, too many fields to check if there is a match. Thanks for the help tho.

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    What about using the php function array_count_values? Query for the names of the weapons then use the function to count how many times the name occurs in the array.

    PHP Code:
    $weaponsquery "SELECT name FROM {{table}} WHERE playerid=' '.$userrow['id']. " ' AND type = '1' ", 'smithcreate);
     
    $counts array_count_values($weaponsquery); 
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #6
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,447
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Possible


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •