Dirty-Rockstar Posted August 17, 2007 Share Posted August 17, 2007 i have snippits of code from templates to help me on my php journey. and now im trying to learn joining tables. I found this code and i was wondering if someone could decrypt the shorthand for me and give me a better example. someone looked at it and said it was a "dirty join" lol could someone make the shorthand better for me so i can actually read it? $inv=mysql_query("SELECT iv.*,i.*,it.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid WHERE iv.inv_userid={$userid} ORDER BY i.itmtype ASC, i.itmname ASC",$c); the only thing i can get out of it is its trying to join 2 or 3 tables...and its ordered first by itemtype and then the name. and $c is the connection from the db but i dont even think you need that. i can understand some, but i thought some experts can help me. someone give me a better example from whatever that german code says? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 17, 2007 Share Posted August 17, 2007 The Mysql website can give you a good understanding of join/queries in queries. They are tool techniques to mysql that make it a lot more powerful and once you master them you can use tables much more efficently. One example is making an internal messaging system. When some one sends a person a message they do it by user names, but for optimization purposes your banning table stores only user ids, problem? Not if you do a query in query. The trick is to structure your queries around making sense for storing the least about of repeated data. In this case we can say select from Banning where banner = (select UserID from Users where Username = $_POST['reciver']) && banned = $_SESSION['UserID'] This is one trick. For your question about join the practicality is developing a single mysql resource that contains all your data you want to use (generally in a loop like while($row = mysql_fetch_array($result)){ This way you can echo out all data without having to create arrays outside of the loop. 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.