two sql queries in one place
<?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
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]'
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...
I think you need brackets in your WHERE
clause:
WHERE user_submitted != '$_SESSION[username]'
AND (home_user = '$_SESSION[username]'
OR away_user = '$_SESSION[username]')
精彩评论