tags:

views:

43

answers:

3
        <?php
    $results = mysql_query("SELECT * FROM ".TBL_SUB_RESULTS."
                           WHERE user_submitted != '$_SESSION[username]' AND home_user = '$_SESSION[username]' OR away_user =   
                           '$_SESSION[username]'  ") ;
    $num_rows = mysql_num_rows($results);
        if ($num_rows > 0)
        { 
            while( $row = mysql_fetch_assoc($results)) 
            {
                extract($row);
                $q = mysql_query("SELECT name FROM ".TBL_FRIENDLY." WHERE id = '$ccompid'");
                while( $row = mysql_fetch_assoc($q)) 
                {
                    extract($row);
                ?>
                    <table cellspacing="10" style='border: 1px dotted' width="300" bgcolor="#eeeeee">
                    <tr>
                    <td><b><? echo $name; ?></b></td>
                    </tr><tr>
                    <td width="100"><? echo $home_user; ?></td>
                    <td width="50"><? echo $home_score; ?></td>
                    <td>-</td>
                    <td width="50"><? echo $away_score; ?></td>
                    <td width="100"><? echo $away_user; ?></td>
                    </tr><tr>
                    <td colspan="2"><A HREF="confirmresult.php?fixid=<? echo $fix_id; ?>">Accept / Decline</a></td>
                    </tr></table><br>
                    <?
                }


            }


        }
        else
        {
            echo "<b>You currently have no results awaiting confirmation</b>";
        }

    ?> 

I am trying to run two queries as you can see. But they aren't both working. Is there a better way to structure this, I am having a brain freeze! Thanks

OOOH by the way, my SQL wont stay in this form! I will protect it afterwards

A: 
SELECT  *
FROM    TBL_SUB_RESULTS ts
LEFT JOIN
        TBL_FRIENDLY tf
ON      tf.id = ts.ccompid
WHERE   ts.user_submitted != '$_SESSION[username]'
        AND ts.home_user = '$_SESSION[username]' OR ts.away_user = '$_SESSION[username]'
Quassnoi
I actually did this but it didnt want to work!
Luke
@Luke: how did it explain its unwillingness to work?
Quassnoi
I have put this in place, but the where part is no longer working.
Luke
@Luke: could you please be more specific in describing your problems? It's very hard to figure out the reason from descriptions like "doesn't want to work" or "the where part is not working". Did it return an error message? The wrong results?
Quassnoi
The way it works is a row from the table should be returned if there is a row where user submitted isnt the user but they are the home or away user. Problem is, since I did this join, thats not longer working. Not it's returning like the user_submitted is the user in question and its not.
Luke
Forget that, I apologise, I had left an old row in where compid was 0, meaning it wasn't picking it up!Thanks for your help
Luke
A: 

For debuging purposes, try to print your queries to the sceen. Check if you find any errors in your final query. You might just have misspelled a variable name.

<?php
$query = "SELECT * FROM ".TBL_SUB_RESULTS." WHERE user_submitted != '$_SESSION[username]' AND home_user = '$_SESSION[username]' OR away_user = '$_SESSION[username]'";
echo "query: ".$query;

$results = mysql_query($query);
// rest of code...
Sebastian
A: 

I think you need brackets in your WHERE clause:

WHERE user_submitted != '$_SESSION[username]' 
    AND (home_user = '$_SESSION[username]' 
        OR away_user = '$_SESSION[username]')
RedFilter