seany123 Posted September 14, 2009 Share Posted September 14, 2009 I have asked this question about 3 times now and none of the times was i able to find the help i needed to complete this task... so now im going to try and explain it to the maximum and hope someone is able to help me. Firstly i have 3 Tables in my database; "player", "blueprint_items", "items". in players all im going to be using is $player->id. but here is the table structure from the other two... -- -- Table structure for table `blueprint_items` -- CREATE TABLE IF NOT EXISTS `blueprint_items` ( `id` int(11) NOT NULL auto_increment, `item_id` int(11) NOT NULL, `name` varchar(255) collate latin1_general_ci NOT NULL default '', `description` text collate latin1_general_ci NOT NULL, `type` enum('weapon','armour','shoe','Consumable','pet','rare','parts','other') collate latin1_general_ci NOT NULL default 'weapon', `Value` int(11) NOT NULL default '0', `shopcost` int(11) NOT NULL default '0', `strengthbonus` int(11) NOT NULL default '0', `defensebonus` int(11) NOT NULL default '0', `speedbonus` int(11) NOT NULL default '0', `powerbonus` int(11) NOT NULL default '0', `torquebonus` int(11) NOT NULL default '0', `weightbonus` int(11) NOT NULL default '0', `img` varchar(255) collate latin1_general_ci NOT NULL, `features` varchar(255) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=96 ; -- -- Table structure for table `items` -- CREATE TABLE IF NOT EXISTS `items` ( `id` int(11) NOT NULL auto_increment, `player_id` int(11) NOT NULL default '0', `item_id` int(11) NOT NULL default '0', `status` enum('equipped','unequipped') collate latin1_general_ci NOT NULL default 'unequipped', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=146 ; Now what im wanted to do is to identify all the rows in "items" which apply to my player.. so i did this query: <?php $query = $db->execute("select * from items where `player_id`=?", array($player->id)); $item = $query->fetchrow(); ?> then i wanted to get all the info from blueprint_items: <?php $query2 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); $item2 = $query2->fetchrow(); ?> but then here is where i hit a snag... what i want to do is only show 1 record from "items" table when the recordcount is bigger than 1.. so i did this.. <?php $query3 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); while($query3->recordcount() <= 1){ ?> Then i realised i needed to get the information from "items" again so i did this... <?php $query4 = $db->execute("select * from `items` where `player_id`=? and `item_id`=? LIMIT=1", array($player->id, $item['item_id'])); ?> But this didnt work... its stilling echoing from all the rows. Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 15, 2009 Author Share Posted September 15, 2009 ANYONE??!?!?!!?? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 15, 2009 Share Posted September 15, 2009 <?php $query2 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); $item2 = $query2->fetchrow(); ?> but then here is where i hit a snag... what i want to do is only show 1 record from "items" table when the recordcount is bigger than 1.. Just use Limit select * from `blueprint_items` where `id`=? LIMIT 0,1 Then i realised i needed to get the information from "items" again so i did this... <?php $query4 = $db->execute("select * from `items` where `player_id`=? and `item_id`=? LIMIT=1", array($player->id, $item['item_id'])); ?> But this didnt work... its stilling echoing from all the rows. Again LIMIT 0,1 Moving to correct section (being an SQL problem) Quote Link to comment Share on other sites More sharing options...
artacus Posted September 15, 2009 Share Posted September 15, 2009 *sarcasm* Yeah! More PHP joins! I hate when I see this done in PHP. This is what your relational database was designed for. Otherwise you might as well be storing your data in text files. I don't know exactly what you're trying to do but a sample query may look like this. SELECT * FROM player p JOIN ( -- This limits to one item per player. -- You may want to use min or some CASE statement to get -- the correct item. SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1 ) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = 1 Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 16, 2009 Author Share Posted September 16, 2009 <?php $query2 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); $item2 = $query2->fetchrow(); ?> but then here is where i hit a snag... what i want to do is only show 1 record from "items" table when the recordcount is bigger than 1.. Just use Limit select * from `blueprint_items` where `id`=? LIMIT 0,1 Then i realised i needed to get the information from "items" again so i did this... <?php $query4 = $db->execute("select * from `items` where `player_id`=? and `item_id`=? LIMIT=1", array($player->id, $item['item_id'])); ?> But this didnt work... its stilling echoing from all the rows. Again LIMIT 0,1 Moving to correct section (being an SQL problem) that made nothing change. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 16, 2009 Share Posted September 16, 2009 if your getting more then one records while using LIMIT 0,1 then you have a code problem. Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 17, 2009 Author Share Posted September 17, 2009 well this is the code... and i cant see anything wrong... <?php include("lib.php"); define("PAGENAME", "Mafia"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); ?> <div id="left_c"> <div class="g_content"><h3> Equipment</h3><div class="g_text"> <table align='center' cellspacing='10'> <?php $current_col = 1; $max_col = 4; $query = $db->execute("select * from items where `player_id`=?", array($player->id)); $item = $query->fetchrow(); $query2 = $db->execute("select * from `blueprint_items` where `id`=? LIMIT 0,1",array($item['item_id'])); $item2 = $query2->fetchrow(); $query3 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['item_id'])); while($query3->recordcount() <= 1){ $query4 = $db->execute("select * from `items` where `player_id`=? and `item_id`=? LIMIT 0,1", array($player->id, $item['item_id'])); $item3 = $query4->fetchrow(); if ($query3->recordcount() <= 1) { //Open new row if first column if($current_col==1) { echo "<tr>\n"; } //Display current record echo "<td>"; echo "<center><img src=\"{$item2['img']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item2['id']}\">{$item2['name']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item3['id']."'>Sell</a>] [<a href='../item.php?market=".$item3['id']."'>Market</a>] <br>[<a href='../item.php?send=".$item3['id']."'>Send</a>] [<a href='../item.php?use=".$item3['id']."'>Use</a>]</center><br>"; echo "</td>\n"; //Close row if last column if($current_col==$max_col) { echo "<tr>\n"; $current_col = 0; //<---Changed } $current_col++; } else if ($query3->recordcount() >= 2) { //Display current record echo "<td>"; echo "<center><img src=\"{$item2['img']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item2['id']}\">{$item2['name']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item3['id']."'>Sell</a>] [<a href='../item.php?market=".$item3['id']."'>Market</a>] <br>[<a href='../item.php?send=".$item3['id']."'>Send</a>] [<a href='../item.php?use=".$item3['id']."'>Use</a>]</center><br>"; echo "<center>Quantity IS EQUAL TOO!!</center>"; echo $query3->recordcount(); echo "</td>\n"; //Close row if last column if($current_col==$max_col) { echo "<tr>\n"; $current_col = 0; //<---Changed } $current_col++; } //Close last row if needed if ($current_col!=1) { for(; $current_col<=$max_col; $current_col++) { echo "<td> </td>\n"; } } } ?> </table> </div></div> Quote Link to comment Share on other sites More sharing options...
kickstart Posted September 17, 2009 Share Posted September 17, 2009 Hi This seems to be a duplicate of :- http://www.phpfreaks.com/forums/index.php/topic,267967.0.html Why are you doing 4 seperate pieces of SQL and then trying to struggle with the results when one single query would appear to do it (example from artacus seems to cover it)? What object are you using to access the database and so what is recordcount? Is it just a count of the number of the current row? You appear to do 2 selects against blueprint_items, but don't actually do anything with the 2nd (not even bring back a row) except check that its recordcount is <= 1. All the best Keith Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 17, 2009 Author Share Posted September 17, 2009 because from what artacus has wrote i cant seem to understand how it works... im just soo sonfused with all this... Quote Link to comment Share on other sites More sharing options...
kickstart Posted September 17, 2009 Share Posted September 17, 2009 iHi His SQL just brings back one row for each. SELECT * FROM player p JOIN ( -- This limits to one item per player. -- You may want to use min or some CASE statement to get -- the correct item. SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1 ) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = 1 I will try and go through it to break it down for you:- SELECT * FROM player p Self explanitory JOIN ( SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1 ) items_sub ON p.id = items_sub.player_id Find the max id and count of ids for the particular player from the items table. This will bring back a single row. So joining this to players gives you the max id and count of ids for that particular player. JOIN items i ON items_sub.id = i.id This gets the rest of the fields from the items table. It gets the ones that have the id that matches the max id found for that player. JOIN blueprint_items bi ON i.id = bi.item_id Get the details for that single item from the blueprint_items table. WHERE p.id = 1 Limit it to the player with the id of 1. Probably not strictly necessary as you have limited it in the section in green This will give you a single row. If you want one row per type of item for a player then the SQL I put in the other thread will do the job:- SELECT a.name, a.someOtherField, b.ItemCount (SELECT item_id, count(id) AS ItemCount FROM items WHERE player_id = 1 GROUP BY item_id)a INNER JOIN blueprint_items b ON a.item_id = b.item_id This kind of thing is what SQL is designed for. You join related data from tables in SQL. Doing queries on the results of queries is pretty inefficient. All the best Keith Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 27, 2009 Author Share Posted September 27, 2009 im still having problems integrating that with my current code.... <?php include("lib.php"); define("PAGENAME", "MafiaKillerz"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); ?> <div id="left_c"> <div class="g_content"><h3> Equipment</h3><div class="g_text"> <table align='center' cellspacing='10'> <?php $current_col = 1; $max_col = 4; // GET ALL FROM ITEMS // TO GET ALL ROWS USING PLAYER->ID. $query = $db->execute("select * from items where `player_id`=?", array($player->id)); $item = $query->fetchrow(); //GET ALL FROM BLUEPRINTS. //TO GET ALL ROWS USING PLAYER-ID & ITEM['id'] $query2 = $db->execute("select * from `blueprint_items` where `id`=? LIMIT 0,1",array($item['id'])); $item2 = $query2->fetchrow(); $query3 = $db->execute("select * from `blueprint_items` where `id`=?",array($item['id'])); while($query3->recordcount() <= 1){ $query4 = $db->execute("select * from `items` where `player_id`=? and `item_id`=? LIMIT 0,1", array($player->id, $item['id'])); $item3 = $query4->fetchrow(); if ($query3->recordcount() <= 1) { //Open new row if first column if($current_col==1) { echo "<tr>\n"; } //Display current record echo "<td>"; echo "<center><img src=\"{$item2['img']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item2['id']}\">{$item2['name']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item3['id']."'>Sell</a>] [<a href='../item.php?market=".$item3['id']."'>Market</a>] <br>[<a href='../item.php?send=".$item3['id']."'>Send</a>] [<a href='../item.php?use=".$item3['id']."'>Use</a>]</center><br>"; echo "</td>\n"; //Close row if last column if($current_col==$max_col) { echo "<tr>\n"; $current_col = 0; //<---Changed } $current_col++; } else if ($query3->recordcount() >= 2) { //Display current record echo "<td>"; echo "<center><img src=\"{$item2['img']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item2['id']}\">{$item2['name']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item3['id']."'>Sell</a>] [<a href='../item.php?market=".$item3['id']."'>Market</a>] <br>[<a href='../item.php?send=".$item3['id']."'>Send</a>] [<a href='../item.php?use=".$item3['id']."'>Use</a>]</center><br>"; echo "<center>Quantity IS EQUAL TOO!!</center>"; echo $query3->recordcount(); echo "</td>\n"; //Close row if last column if($current_col==$max_col) { echo "<tr>\n"; $current_col = 0; //<---Changed } $current_col++; } //Close last row if needed if ($current_col!=1) { for(; $current_col<=$max_col; $current_col++) { echo "<td> </td>\n"; } } } ?> </table> </div></div> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted September 27, 2009 Share Posted September 27, 2009 That's a shame, if only we knew what the problems were maybe we could help! oh well! Quote Link to comment Share on other sites More sharing options...
kickstart Posted September 27, 2009 Share Posted September 27, 2009 Hi It is difficult to work out what you really want, as the php doesn't really go with what you have said you want. This is my best guess as what you want:- <?php include("lib.php"); define("PAGENAME", "MafiaKillerz"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); ?> <div id="left_c"> <div class="g_content"><h3> Equipment</h3><div class="g_text"> <table align='center' cellspacing='10'> <?php $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); $item = $query->fetchrow(); while($item = $query->fetchrow()) { echo "<tr>\n"; echo "<td>"; echo "<center><img src=\"{$item['blueprintimg']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item['blueprintid']}\">{$item['blueprintname']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item['itemid']."'>Sell</a>] [<a href='../item.php?market=".$item['itemid']."'>Market</a>] <br>[<a href='../item.php?send=".$item['itemid']."'>Send</a>] [<a href='../item.php?use=".$item['itemid']."'>Use</a>]</center><br>"; echo "</td>\n"; echo "<tr>\n"; } ?> </table> </div></div> All the best Keith Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 29, 2009 Author Share Posted September 29, 2009 Hi It is difficult to work out what you really want, as the php doesn't really go with what you have said you want. This is my best guess as what you want:- <?php include("lib.php"); define("PAGENAME", "MafiaKillerz"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); ?> <div id="left_c"> <div class="g_content"><h3> Equipment</h3><div class="g_text"> <table align='center' cellspacing='10'> <?php $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); $item = $query->fetchrow(); while($item = $query->fetchrow()) { echo "<tr>\n"; echo "<td>"; echo "<center><img src=\"{$item['blueprintimg']}\" width='80' height='80' style=\"border: 1px solid #CC9900\"></center>"; echo "<center><a href=\"../description.php?id={$item['blueprintid']}\">{$item['blueprintname']}</a></center>"; echo "<center>[<a href='../item.php?sell=".$item['itemid']."'>Sell</a>] [<a href='../item.php?market=".$item['itemid']."'>Market</a>] <br>[<a href='../item.php?send=".$item['itemid']."'>Send</a>] [<a href='../item.php?use=".$item['itemid']."'>Use</a>]</center><br>"; echo "</td>\n"; echo "<tr>\n"; } ?> </table> </div></div> All the best Keith thankyou... its now giving me a error: Fatal error: Call to a member function fetchrow() on a non-object on line 18.... which is this bit: $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); $item = $query->fetchrow(); while($item = $query->fetchrow()) { Quote Link to comment Share on other sites More sharing options...
kickstart Posted September 29, 2009 Share Posted September 29, 2009 Hi Suggests there is an error with the SQL. Can't see anything obvious but maybe a typo. Copy the SQL, and try it in phpmyadmin or whatever other package you have for MySQL and see what the real error is. All the best Keith Quote Link to comment Share on other sites More sharing options...
seany123 Posted September 30, 2009 Author Share Posted September 30, 2009 i went into myphpadmin and went into the sql bit and pasted this exactly: $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); $item = $query->fetchrow(); and it came back with this error: Error There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem ERROR: Unknown Punctuation String @ 13 STR: -> SQL: $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id));$query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id));$query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); SQL query: $query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?", array($player->id)); MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = $db->execute("SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.n' at line 1 Quote Link to comment Share on other sites More sharing options...
seany123 Posted October 1, 2009 Author Share Posted October 1, 2009 anyone know how to fix this?? Quote Link to comment Share on other sites More sharing options...
cags Posted October 1, 2009 Share Posted October 1, 2009 I can certainly tell you why your test didn't work. The code you pasted contains PHP code, something that would make no sense to PHPMyAdmin since it only parses MySQL. What you would need to put into PHPMyAdmin is something like... SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN (SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ?????????? Only replacing ?????????? with a valid p.id Looking at the actual query there is some syntax I don't recognise, but it's not to say they're wrong, my MySQL knowledge isn't especially in-depth, the parts I'm not sure about are... FROM player p JOIN items i JOIN blueprint_items bi Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 1, 2009 Share Posted October 1, 2009 Copy the SQL, and try it in phpmyadmin or whatever other package you have for MySQL and see what the real error is. i went into myphpadmin and went into the sql bit and pasted this exactly: ONLY post the query and the value passed SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id as itemid FROM player p JOIN ( SELECT player_id, MAX(id) AS id, COUNT(id) AS num_items FROM items WHERE player_id = 1 ) items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id = ? replace ? with a player ID Humm not sure about that join Quote Link to comment Share on other sites More sharing options...
seany123 Posted October 3, 2009 Author Share Posted October 3, 2009 okay i tried that now i have this error: Error SQL query: Documentation SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id AS itemid FROM player p JOIN ( SELECT player_id, MAX( id ) AS id, COUNT( id ) AS num_items FROM items WHERE player_id =1 )items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id =1 MySQL said: Documentation #1146 - Table 'maf10000_db1.player' doesn't exist Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 3, 2009 Share Posted October 3, 2009 Well that's strange Firstly i have 3 Tables in my database; "player", "blueprint_items", "items". okay i tried that now i have this error: MySQL said: Documentation #1146 - Table 'maf10000_db1.player' doesn't exist which mean the table 'player' does NOT exist.. So what should the table name be ? Quote Link to comment Share on other sites More sharing options...
seany123 Posted October 4, 2009 Author Share Posted October 4, 2009 ooh crap the table is actually called players. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 4, 2009 Share Posted October 4, 2009 update FROM player p to FROM players p Quote Link to comment Share on other sites More sharing options...
seany123 Posted October 5, 2009 Author Share Posted October 5, 2009 this is what i got: MySQL returned an empty result set (i.e. zero rows). (Query took 0.0003 sec) SQL query: SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id AS itemid FROM players p JOIN ( SELECT player_id, MAX( id ) AS id, COUNT( id ) AS num_items FROM items WHERE player_id =1 )items_sub ON p.id = items_sub.player_id JOIN items i ON items_sub.id = i.id JOIN blueprint_items bi ON i.id = bi.item_id WHERE p.id =1 upon having a good look at the SQL im noticing a couple of problems... im not good with this so maybe they are supposed to be this way.... SELECT bi.img AS blueprintimg, bi.id AS blueprintid, bi.name AS blueprintname, i.id AS itemid FROM players p from what thats saying is looks like its trying to get img, id and name all from the "players" tables where it should be trying to get it from the "blueprint_items" table. Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi No, it is getting them from the blueprint table . blueprint_items has been aliased as bi, hence it is selecting bi.img. Do you defiantly have a player with an id of 1 who has some items, and those items have a matching record on the blueprint_items table? All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.