Jump to content

learning about joining tables...help?


Dirty-Rockstar

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.