Inner Join Help

Discussion in 'PHP' started by MTA, Mar 3, 2009.

  1. #1
    I need some help..

    I am making a script that will use INNER JOIN> I have 5 tables

    I want it be able to show today post only..
    but it is not wokring..
    
    
    <?
    error_reporting(E_ALL);
    
    $con = mysql_connect('localhost', 'user', 'pass');
    if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
    
    mysql_select_db("test", $con);
    
    $today = strtotime( 'today' );
    //select most recent dates and unique IDs for mood, flirt, video, journal, main
    $sql="SELECT t1.id AS mood_id, t1.date AS mood_date, t2.date AS video_date, t2.id AS video_id, t4.time AS flirt_date, t4.id AS flirt_id, t5.time AS journal_date, t5.id AS journal_id, t6.time AS main_date,  t6.id AS main_id
    FROM user AS t3
    INNER JOIN mood AS t1 ON t1.date < $today 
    INNER JOIN video AS t2 ON t2.date < $today
    INNER JOIN flirt AS t4 ON t4.time < $today
    INNER JOIN journal AS t5 ON t5.time < $today
    INNER JOIN main AS t6 ON t6.time < $today
    WHERE (
    (
    t3.user = t1.userid
    )
    OR (
    t3.user = t2.userid
    )
    OR (
    t3.user = t4.user
    )
    OR (
    t3.user = t5.user
    )
    OR (
    t3.user = t6.user
    )
    )
    LIMIT 1";
    
    //print $sql;
    $result = mysql_query($sql);
    
    //let's grab all the data and parse it through from the query above
    while($row = mysql_fetch_array($result))
     {
    
    print "<pre>";
    print_r($row);
    print "</pre>";
    
    
    
     }
    
    mysql_close($con);
    
    ?>
    Code (markup):


    But this one is working
    
    
    $today = strtotime( 'today' );
    $a = mysql_query("SELECT * FROM mood WHERE date > $today ORDER BY date DESC LIMIT 0,1" );
    
    while ($f =mysql_fetch_array($a))
    
    		{
    
    
    
    echo '<li><img src=\'http://mateable.com/member/mood/css/images/bullet.gif\' alt=\'-\' />'.$f['userid'].' Updated Status and Mood</li>';
    
    
    
    }
    Code (markup):
    Not sure.. how to get the top one working
     
    MTA, Mar 3, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    INNER JOIN mood AS t1 ON t3.user = t1.userid AND t1.date < $today
     
    SmallPotatoes, Mar 3, 2009 IP