...

View Full Version : Resolved Matching sets, count?



myfayt
09-07-2011, 04:44 PM
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?


$epquery = doquery("SELECT * FROM {{table}} WHERE name='".$userrow['guildname']."'", "allianceequip");

kickboxinghelen
09-07-2011, 05:00 PM
$epquery = doquery("SELECT count(name) from {{table}} WHERE name='".$userrow['guildname']."' AND bonusattack ='".$userrow['bonusattack']."' AND requirement = '".$userrow['requirement']."' AND type = '".$userrow['type']."'","allianceequip");

myfayt
09-07-2011, 05:33 PM
Thanks and one more question, how would I display that into a variable? Such as Matched: $sets

myfayt
09-08-2011, 06:56 PM
I tried to set it as a mysql_fetch_array but it didn't work. :(

Chris Hick
09-08-2011, 07:52 PM
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?

myfayt
09-08-2011, 08:34 PM
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.

Chris Hick
09-08-2011, 11:35 PM
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.

myfayt
09-08-2011, 11:55 PM
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.

myfayt
09-09-2011, 01:25 AM
It's not working...


$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)

Inigoesdr
09-09-2011, 05:07 PM
It's not working...


$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:

echo mysql_num_rows($setsq);

myfayt
09-09-2011, 07:34 PM
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?


$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.

Inigoesdr
09-09-2011, 11:42 PM
It's outputting twice because it's inside of your while() (http://php.net/while) loop and your $epquery query is returning 2 rows.

myfayt
09-10-2011, 07:02 PM
Solved, I can't edit the post, so I will just post it here.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum