View Full Version : Resolved Matching sets in query

08-26-2011, 01:41 AM
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.

$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>';

Chris Hick
08-26-2011, 05:47 PM
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.

08-26-2011, 06:14 PM
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.

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

08-26-2011, 08:31 PM
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. :thumbsup:

Chris Hick
08-26-2011, 08:36 PM
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.

$weaponsquery = "SELECT name FROM {{table}} WHERE playerid=' '.$userrow['id']. " ' AND type = '1' ", 'smithcreate');

$counts = array_count_values($weaponsquery);

08-26-2011, 09:10 PM