I’m trying to display information based on a cross-reference of table data from 3 tables using multiple ‘while’s’. The problem I’m having is that the data inside the innermost ‘while’ is being displayed 6881 times – the exact number of entries in the first table. The rest seems to be working fine.
Working example: http://l2-x.no-ip.org/search.html Enter the term “bone” and hit enter. Then view the details in the “ITEM” column. Repeated identical monster entries.
Tables:
etcitem
item_id (A), name, crystal_type
droplist
mobId (B), itemId (matches up with A), min, max, category, chance
npc
id (matches up with B), name, level
What I’m doing is trying to display items queried b y name or item ID, then for each one, display which monster drops it - by referencing the item’s ID in ‘etcitem’ table to the matching ID in ‘droplist’ table, then take the monster [mobId] and drop chance from that droplist entry, and again reference it to the npc table to display the monster’s name and level)
(In the back of my mind, the 2 ‘names’ in the query might get confused?)
$edrop = mysql_query("SELECT etcitem.item_id, etcitem.name, etcitem.crystal_type, droplist.mobId, droplist.itemId, droplist.min, droplist.max, droplist.category, droplist.chance, npc.id, npc.name, npc.level FROM etcitem, droplist, npc WHERE $eitem = droplist.itemId AND npc.id = droplist.mobId ORDER BY npc.level ASC");
Snippet:
[code]if($method == “EQUALS”)
{
$searche = mysql_query(“SELECT * FROM etcitem WHERE $type = ‘$query’ ORDER BY $omethod $smethod”);
$searcha = mysql_query(“SELECT * FROM armor WHERE $type = ‘$query’ ORDER BY $omethod $smethod”);
$searchw = mysql_query(“SELECT * FROM weapon WHERE $type = ‘$query’ ORDER BY $omethod $smethod”);
} else {
$searche = mysql_query(“SELECT * FROM etcitem WHERE $type LIKE ‘$query’ ORDER BY $omethod $smethod”);
$searcha = mysql_query(“SELECT * FROM armor WHERE $type LIKE ‘$query’ ORDER BY $omethod $smethod”);
$searchw = mysql_query(“SELECT * FROM weapon WHERE $type LIKE ‘$query’ ORDER BY $omethod $smethod”);
}
echo “”;
echo “
”;
$x=1; if(mysql_num_rows($searche) > 0)
} else { echo “
}[/code] [hr] ENTIRE CODE:: [code] body { scrollbar-base-color: #888888; scrollbar-arrow-color: #888888; scrollbar-3dlight-color: #888888; scrollbar-darkshadow-color: #888888; scrollbar-face-color: #000000; scrollbar-highlight-color: #000000; scrollbar-shadow-color: #888888; scrollbar-track-color: #888888; } <?php include 'ip.php'; $connect = @mysql_pconnect( $server, $username, $password ) or die(); $db_select = @mysql_select_db( $database, $connect ) or die(); //show details by default? (0 or 1) $show = 1; if($show == 1) { $divdef = "display:block"; } else { $divdef = "display:none"; } $a=0; $e=0; $w=0; $query = mysql_real_escape_string($_POST['query']); $type = mysql_real_escape_string($_POST['type']); $method = mysql_real_escape_string($_POST['method']); $smethod = mysql_real_escape_string($_POST['smethod']); $omethod = mysql_real_escape_string($_POST['omethod']); if($method == "CONT") { $queryx = "%"; $query .= $queryx; $queryx .= $query; $query = $queryx; $queryx = ""; } if($method == "BEGIN") { $queryx = "%"; $query .= $queryx; $queryx = ""; } if($method == "END") { $queryx = "%"; $queryx .= $query; $query = $queryx; $queryx = ""; } if($method == "EQUALS") { $searche = mysql_query("SELECT * FROM etcitem WHERE $type = '$query' ORDER BY $omethod $smethod"); $searcha = mysql_query("SELECT * FROM armor WHERE $type = '$query' ORDER BY $omethod $smethod"); $searchw = mysql_query("SELECT * FROM weapon WHERE $type = '$query' ORDER BY $omethod $smethod"); } else { $searche = mysql_query("SELECT * FROM etcitem WHERE $type LIKE '$query' ORDER BY $omethod $smethod"); $searcha = mysql_query("SELECT * FROM armor WHERE $type LIKE '$query' ORDER BY $omethod $smethod"); $searchw = mysql_query("SELECT * FROM weapon WHERE $type LIKE '$query' ORDER BY $omethod $smethod"); } echo ""; echo "
|