...

View Full Version : Complex Query



myfayt
11-16-2011, 07:11 PM
I have two tables dk_smithcreate and dk_items.

The items table has all the weapons, armor, shields in the game. Ultimately I need to extract the id in the while loop. Because the id in the smithcreate table is completely different. So I want to match them by names.

The names in both tables are identical. smithcreate is the players inventory, so it needs to check playerid and name from smithcreate to display in the while loop.

Next it needs to match that name to the name field in the items table. Then extract that id from the items table into a link.

Everything works, except it's displaying the id from the smithcreate table instead of the item from the items table.


Part to Fix

$mequery = doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."'", 'smithcreate');
$test = mysql_fetch_array($mequery);

$aquery = "SELECT dk_smithcreate.name, dk_items.name FROM dk_smithcreate, dk_smithcreate
WHERE dk_smithcreate.playerid = '$userrow[id]'
AND dk_smithcreate.name = '$test['name']'
ORDER BY dk_items.name";


if (mysql_num_rows($mequery) == 0) {
$page .= '<tr><td><p>You have no equipment in your inventory.</td></tr></table>';
}

if {
while ($wrow = mysql_fetch_array($aquery)) {



This is the whole function

function giveequip()
{

global $userrow, $numqueries;

$townquery = doquery("SELECT name,innprice FROM {{table}} WHERE latitude='" . $userrow["latitude"] . "' AND longitude='" . $userrow["longitude"] . "' AND `realm` = {$userrow['realm']} LIMIT 1", "towns");
if (mysql_num_rows($townquery) != 1)
{
display("<p>You cannot access this Area outside of town. You may now return to <a href=\"index.php\">exploring</a>.", "Error");
}
$townrow = mysql_fetch_array($townquery);
$updatequery = doquery("UPDATE {{table}} SET location='Alliance Armory' WHERE id='" . $userrow["id"] . "' LIMIT 1", "users");

$alquery = doquery("SELECT * FROM {{table}} WHERE name='".$userrow['guildname']."' LIMIT 1", "alliances");
$alrow = mysql_fetch_array($alquery);

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

$mequery = doquery("SELECT * FROM {{table}} WHERE playerid='".$userrow['id']."'", 'smithcreate');



$title = 'Alliance Armory';
$page = "<table width='100%' border='1'><tr><td class='title'><a href='index.php'>Town</a> > <a href='courtyard.php?do=main'>Courtyard</a> > <a href='alliance.php'>Alliance Riyad</a> > <a href='alliance.php?do=donateequip'>Alliance Armory</a></td></tr></table><p>";
$page .= "Welcome the the ".$alrow['name']." Armory. View the list of available equipment below. If you wish to donate equipment to the alliance, click <a href='alliance.php?do=giveequip'>here</a><br />If you need to borrow anything, please contact one of the alliance staff members.<br /><br />";

$page .= '<table width="95%"><tr><td><b>Weapon Name</b></td><td><b>Min Level</b></td><td><b>Dam/Def</b></td><td><b>Class</b></td><td><b>Upgrade</b></td><td><b>Action</b></td></tr>';
if (mysql_num_rows($mequery) == 0) {
$page .= '<tr><td><p>You have no equipment in your inventory.</td></tr></table>';
}
else {
while ($wrow = mysql_fetch_array($mequery)) {

if ($wrow['class'] == 1) {
$weapon1 = 'Enchantress';
}
elseif ($wrow['class'] == 2) {
$weapon1 = 'Knight';
}
elseif ($wrow['class'] == 4) {
$weapon1 = 'Archer';
}
elseif ($wrow['class'] == 7) {
$weapon1 = 'Thief';
}
else {
$weapon1 = 'None';
}

if ($wrow['equipped'] == 'No') {
$setweapon = "<a href='alliance.php?do=giveequip2:".$wrow['id']."'>GIVE</a>";
}
else {
$setweapon = "EQUIPPED";
}

$page .= "<tr><td>".$wrow['name']."</td><td>Lvl ".$wrow['requirement']."</td><td>+".$wrow['attribute']."</td><td>$weapon1</td><td>+".$wrow['bonusattack']."</td><td>$setweapon</td></tr>";
}
$page .= '</table>';
}

display($page, $title);

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum