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 13 of 13
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts

    Matching sets, count?

    I need a query to match Identical values and count how many of them are alike.

    The standard query looks like this, this is the same table it needs to come from, but how would I get it to match bonusattack, requirement, and type, and display in a variable how many match the same exact values?

    PHP Code:
    $epquery doquery("SELECT * FROM {{table}} WHERE name='".$userrow['guildname']."'""allianceequip"); 
    Last edited by Inigoesdr; 09-10-2011 at 08:27 PM.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $epquery = doquery("SELECT count(name) from {{table}} WHERE name='".$userrow['guildname']."' AND bonusattack ='".$userrow['bonusattack']."' AND requirement = '".$userrow['requirement']."' AND type = '".$userrow['type']."'","allianceequip");

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Thanks and one more question, how would I display that into a variable? Such as Matched: $sets

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    I tried to set it as a mysql_fetch_array but it didn't work.

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    So, you are saying you need to look through a database and pull out how many items meet the criteria you have, then see how many matches their are?

    EDIT: If so, why not use the query above, then use mysql_num_rows to see how many rows their are of that and store that number in a variable $set?
    Last edited by Chris Hick; 09-08-2011 at 06:55 PM.
    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,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    I am just being a little brain dead today, can I make it into a variable like this?

    $sets = "mysql_num_rows($setsquery)";

    Because I want to avoid a while loop and stuff.

  • #7
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Yeah, you could certainly do that, but take into mind that mysql_num_rows is going to return how many items is in that query. So, if you use your criteria its going to return to you how many there are for one matching item.
    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. ^_^

  • #8
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Yeah I need sets based on the exact query. Meaning if all 3 fields are a match, then it adds +1 row.

    I just don't want the same exact item to be repeated over and over.

  • #9
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    It's not working...

    PHP Code:
    $setsq doquery("SELECT count(name) from {{table}} WHERE name='".$userrow['guildname']."' AND bonusattack ='".$userrow['bonusattack']."' AND requirement = '".$userrow['requirement']."' AND type = '".$userrow['type']."'","allianceequip");
            
    $setsshow "mysql_num_rows($setsq)";

    echo 
    "$setsshow"
    Returns this

    mysql_num_rows(Resource id #11)

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by myfayt View Post
    It's not working...

    PHP Code:
    $setsq doquery("SELECT count(name) from {{table}} WHERE name='".$userrow['guildname']."' AND bonusattack ='".$userrow['bonusattack']."' AND requirement = '".$userrow['requirement']."' AND type = '".$userrow['type']."'","allianceequip");
            
    $setsshow "mysql_num_rows($setsq)";

    echo 
    "$setsshow"
    Returns this
    As it should.. you are outputting a string. If you want to actually run the function it would look like this:
    PHP Code:
    echo mysql_num_rows($setsq); 

  • #11
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Thanks, now it shows 1. However when two match, it's giving me a double record instead of just putting a 2. Can you help me with that?

    PHP Code:
    $page .= '<table width="95%">';

            
    $page .= '<tr><td><b>Equipment Name</b></td><td><b>Min. Level</b></td><td><b>Dam/Def</b></td><td><b>Upgrade Bonus</b></td><td><b>Class</b></td><td><b>Type</b></td><td><b>Sets</b></td></tr>';

            if (
    mysql_num_rows($epquery) == 0) {
              
    $page .= '<tr><td><p>Armory Empty!</td></tr>';
            }
            else {

             while (
    $aerow mysql_fetch_array($epquery)) {

             
    $setsq doquery("SELECT count(name) from {{table}} WHERE name='".$userrow['guildname']."' AND bonusattack ='".$userrow['bonusattack']."' AND requirement = '".$userrow['requirement']."' AND type = '".$userrow['type']."'","allianceequip");


             
    //START CLASS CHANGE
             
    if ($aerow['class'] == 1) {
               
    $theclass 'Enchantress';
             }
             elseif (
    $aerow['class'] == 2) {
               
    $theclass 'Knight';
             }
             elseif (
    $aerow['class'] == 4) {
               
    $theclass 'Archer';
             }
             elseif (
    $aerow['class'] == 7) {
               
    $theclass 'Thief';
             }
             
    //END CLASS CHANGE
             
             //START TYPE CHANGE
             
    if ($aerow['type'] == 1) {
          
    $eq1 'Weapon';
        }
        elseif (
    $aerow['type'] == 2) {
          
    $eq1 'Armor';
        }
        else {
          
    $eq1 'Shield';
        }
             
    //END TYPE CHANGE

             
    $page .= "<tr><td>".$aerow['name']."</td><td>".$aerow['requirement']."</td><td>+".$aerow['attribute']."</td><td>+".$aerow['bonusattack']."</td><td>$theclass</td><td>".mysql_num_rows($setsq)." Sets</td><td><b>1</b></td></tr>";
             } 
    //END WHILE LOOP

            
    //END ELSE

            
    $page .= '</table>'
    EDIT: By the way, I just noticed it's in the wrong <TD> tag, but still it should be a 2 instead of a double post.
    Attached Thumbnails Attached Thumbnails Matching sets, count?-doubleset.jpg  

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    It's outputting twice because it's inside of your while() loop and your $epquery query is returning 2 rows.

  • #13
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,453
    Thanks
    71
    Thanked 102 Times in 101 Posts
    Solved, I can't edit the post, so I will just post it here.


  •  

    Posting Permissions

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