Web Analytics Made Easy -
StatCounter Matching sets in query - CodingForum

Announcement

Collapse
No announcement yet.

Matching sets in query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resolved 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; Aug 26, 2011, 02:32 PM.
    Been a sign maker for 8 years. My business:
    American Made Signs

  • #2
    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. ^_^

    Comment


    • #3
      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'); 
      Been a sign maker for 8 years. My business:
      American Made Signs

      Comment


      • #4
        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.
        Been a sign maker for 8 years. My business:
        American Made Signs

        Comment


        • #5
          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. ^_^

          Comment


          • #6
            Possible
            Been a sign maker for 8 years. My business:
            American Made Signs

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎