WEB manually writing joins ftl

Discussion in 'OT Technology' started by biawokauns, Jun 16, 2008.

  1. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    I'm doing some shit in PHP and I haven't written a manual join in forever :hsugh:
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Long ass massive queries ftl. Although sometimes they seem somewhat of an accomplishment when you finished it. :o
     
  3. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    sometimes, but not usually :o

    I'm not even doing any crazy joins, just a rating table with the main site table :squint:

    has_many :ratings >

    $q = "SELECT shit_posts.*, ratings.total_votes, ratings.total_value FROM shit_posts, ratings WHERE shit_posts.id = ratings.id ORDER BY ratings.total_votes DESC, ratings.total_value DESC";
     
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Why aren't you using rails? :dunno:
     
  5. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    i'm workin on a site with a buddy, and his managed box doens't support rails. he has an unmetered 10mbit line right now, and we're doing some image shit; so I figured I'd do it in PHP :o
     
  6. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
    $q = "SELECT s.*, r.total_votes, r.total_value FROM shit_posts s, ratings r WHERE s.id = r.id ORDER BY r.total_votes DESC, r.total_value DESC";

    can save some typing doing it that way, but yeah...im starting to like rails the more I use it
     
  7. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    haha i love working with joined tables. i think it's actually fun. i think i want to learn more about databases to get into more advanced database queries. i like the challenge of getting information of a bunch of different tables.
     
  8. Josh

    Josh Guest

    This should get you started

    Code:
    $qry = "SELECT `table1`.`field1`,`table2`.`field1`
            FROM `table2`
            LEFT JOIN `table1` ON `table1`.`field1` = `table2`.`field2'
            WHERE `table1`.`field1`='$someValue'"; 
    
     
  9. Josh

    Josh Guest

    If the column names are unqiue to one table or the other you can select them with that statement above ^^^ without using the table.fieldname, just use `fieldname`
     
  10. lukin87

    lukin87 New Member

    Joined:
    Jan 11, 2008
    Messages:
    135
    Likes Received:
    0
    i've been working heaps with mysql stored procedures recently... sometimes they are hellishly painful.. and other times they are just glorious.
     

Share This Page