Jump to content

Search the Community

Showing results for tags 'while multiple table select'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. 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?) SNIPPET:: 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 "<center>"; echo "<table border=0 width=100% cellpadding=0 cellspacing=0><tr><td align=center valign=top>"; $x=1; if(mysql_num_rows($searche) > 0) { echo "<table border=1 width=100% cellpadding=0 cellspacing=0>"; echo "<tr style=background-color:#00CC00><td align=center colspan=2><b>ITEMS</b></td></tr>"; echo "<tr style=background-color:#00CC00><td align=center><b>Item ID</b></td><td align=center><b>Name</b></td></tr>"; $e=0; while ($row = mysql_fetch_assoc($searche)) { echo "<tr style=background-color:green;cursor:move onclick=toggle('y".$x."') title='Click to toggle info'><td align=center><b>".$row['item_id']."</b></td><td align=center><b>".$row['name']."</b></td></tr>"; $rowup = strtoupper($row['crystal_type']); echo "<tr style=background-color:#005500><td align=center colspan=2><div id=y".$x." style=".$divdef.">Grade: ".$rowup; $eitem = $row['item_id']; // $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"); if(mysql_num_rows($edrop) > 0) { while ($edrow = mysql_fetch_assoc($edrop)) { echo "<br>Monster: ".$edrow['name']." Lvl: ".$edrow['level']; if($edrow['category'] == -1) { $edtype = "Spoiled"; } else { $edtype = "Dropped"; } $edper = ($edrow['chance'] / 10000); echo "<br>".$edtype." ".$edper."%"; } } // echo "</div></td></tr>"; $x++; $e++; } echo "</table>"; } else { echo "<table border=1 width=100% cellpadding=0 cellspacing=0><tr style=background-color:green><td align=center colspan=2><b>No results found!</b></td></tr></table>"; } ENTIRE CODE:: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="stylez.css" rel="stylesheet" type="text/css" /> <!--[if IE 6]> <style> #main {height:243px;} </style> <![endif]--> <style> 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; } </style> <script type="text/javascript"> function toggle(id) { var e = document.getElementById(id); e.style.display = ((e.style.display!='none') ? 'none' : 'block'); } </script> </head> <body style=background-color:transparent onload=this.focus() topmargin=0 leftmargin=0 bottommargin=0 rightmargin=0> <!-- <div id="menu2" style=width:582px;float:center> --> <?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 "<center>"; echo "<table border=0 width=100% cellpadding=0 cellspacing=0><tr><td align=center valign=top>"; $x=1; if(mysql_num_rows($searche) > 0) { echo "<table border=1 width=100% cellpadding=0 cellspacing=0>"; echo "<tr style=background-color:#00CC00><td align=center colspan=2><b>ITEMS</b></td></tr>"; echo "<tr style=background-color:#00CC00><td align=center><b>Item ID</b></td><td align=center><b>Name</b></td></tr>"; $e=0; while ($row = mysql_fetch_assoc($searche)) { echo "<tr style=background-color:green;cursor:move onclick=toggle('y".$x."') title='Click to toggle info'><td align=center><b>".$row['item_id']."</b></td><td align=center><b>".$row['name']."</b></td></tr>"; $rowup = strtoupper($row['crystal_type']); echo "<tr style=background-color:#005500><td align=center colspan=2><div id=y".$x." style=".$divdef.">Grade: ".$rowup; $eitem = $row['item_id']; // $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"); if(mysql_num_rows($edrop) > 0) { while ($edrow = mysql_fetch_assoc($edrop)) { echo "<br>Monster: ".$edrow['name']." Lvl: ".$edrow['level']; if($edrow['category'] == -1) { $edtype = "Spoiled"; } else { $edtype = "Dropped"; } $edper = ($edrow['chance'] / 10000); echo "<br>".$edtype." ".$edper."%"; } } // echo "</div></td></tr>"; $x++; $e++; } echo "</table>"; } else { echo "<table border=1 width=100% cellpadding=0 cellspacing=0><tr style=background-color:green><td align=center colspan=2><b>No results found!</b></td></tr></table>"; } echo "</td><td align=center valign=top>"; if(mysql_num_rows($searcha) > 0) { echo "<table border=1 width=100% cellpadding=0 cellspacing=0>"; echo "<tr style=background-color:cyan><td align=center colspan=2><b>ARMORS</b></td></tr>"; echo "<tr style=background-color:cyan><td align=center><b>Item ID</b></td><td align=center><b>Name</b></td></tr>"; $a=0; while ($row = mysql_fetch_assoc($searcha)) { echo "<tr style=background-color:#008888;cursor:move onclick=toggle('y".$x."') title='Click to toggle info'><td align=center><b>".$row['item_id']."</b></td><td align=center><b>".$row['name']."</b></td></tr>"; $rowup = strtoupper($row['crystal_type']); $rowbody = strtoupper($row['bodypart']); if($rowbody == "REAR,LEAR") { $rowbody = "EARRING"; } if($rowbody == "RFINGER,LFINGER") { $rowbody = "RING"; } if($rowbody == "NECK") { $rowbody = "NECKLACE"; } if($rowbody == "FEET") { $rowbody = "BOOTS"; } if($rowbody == "DHAIR") { $rowbody = "MASK/HAIR"; } if($rowbody == "HAIR") { $rowbody = "MASK/HAIR"; } if($rowbody == "FACE") { $rowbody = "MASK/HAIR"; } $rowtype = strtoupper($row['armor_type']); echo "<tr style=background-color:#005555><td align=center colspan=2><div id=y".$x." style=".$divdef.">Grade: ".$rowup." Body: ".$rowbody."<br>Type: ".$rowtype." P.Def: ".$row['p_def']." M.Def: ".$row['m_def']."</div></td></tr>"; $x++; $a++; } echo "</table>"; } else { echo "<table border=1 width=100% cellpadding=0 cellspacing=0><tr style=background-color:cyan><td align=center colspan=2><b>No results found!</b></td></tr></table>"; } echo "</td><td align=center valign=top>"; if(mysql_num_rows($searchw) > 0) { echo "<table border=1 width=100% cellpadding=0 cellspacing=0>"; echo "<tr style=background-color:red><td align=center colspan=2><b>WEAPONS</b></td></tr>"; echo "<tr style=background-color:red><td align=center><b>Item ID</b></td><td align=center><b>Name</b></td></tr>"; $w=0; while ($row = mysql_fetch_assoc($searchw)) { if($row['bodypart'] == "rhand") { $wield = "1-Hand"; } if($row['bodypart'] == "lrhand") { $wield = "2-Handed"; } if($row['bodypart'] == "lhand") { $wield = "Shield"; } echo "<tr style=background-color:#AF0000;cursor:move onclick=toggle('y".$x."') title='Click to toggle info'><td align=center><b>".$row['item_id']."</b></td><td align=center><b>".$row['name']."</b></td></tr>"; $rowup = strtoupper($row['crystal_type']); echo "<tr style=background-color:#880000><td align=center colspan=2><div id=y".$x." style=".$divdef.">Grade: ".$rowup." Wield: ".@$wield; if($wield == "Shield") { echo "<br>Shield Defense: ".$row['shield_def']." Shield Defense Rate: ".$row['shield_def_rate']; } else { echo "<br>P.Dmg: ".$row['p_dam']." M.Dmg: ".$row['m_dam']; } echo "</div></td></tr>"; $x++; $w++; } echo "</table>"; } else { echo "<table border=1 width=100% cellpadding=0 cellspacing=0><tr style=background-color:red><td align=center colspan=2><b>No results found!</b></td></tr></table>"; } echo "</td></tr></table>"; $t = (($e) + ($a) + ($w)); if($t == 0) { $t = "no"; } echo "<script>alert('Found ".$t." result(s)!')</script>"; mysql_close(); ?> <!-- </div> --> </body> </html> EDITED by: Ch0cu3r - When posting code please use tags
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.