onthespot Posted October 7, 2009 Share Posted October 7, 2009 This would not appear to be an sql problem. So thats why i have placed it in the php forum $archive2="SELECT comp FROM confirmedresults WHERE home_user = '$suser' OR away_user = '$suser'"; $archq2=mysql_query($archive2); while($row=mysql_fetch_assoc($archq2)){ $comp_name2=$row['comp']; } $archive="SELECT * FROM archive WHERE comp_name = '$comp_name2' "; $archq=mysql_query($archive); $num_rows = mysql_num_rows($archq); echo $num_rows; The $num_rows is coming back at 0. I have checked the sql and it works. I have echoed $comp_name2 and that comes back with what i would expect. So somewhere the comp_name = '$comp_name2' isnt working. Its not bringing back what i want. Have you come across anything like this before? Quote Link to comment Share on other sites More sharing options...
trq Posted October 7, 2009 Share Posted October 7, 2009 Why are you using two queries in the first place instead of a JOIN? Quote Link to comment Share on other sites More sharing options...
onthespot Posted October 7, 2009 Author Share Posted October 7, 2009 Just thought that was the best way to do it? Could you suggest something else that would actually work? Quote Link to comment Share on other sites More sharing options...
trq Posted October 7, 2009 Share Posted October 7, 2009 $sql = "SELECT * FROM archive LEFT JOIN confirmed_results ON archive.comp_name = confirmedresults.comp_name AND confirmedresults.away_user = '$suser'"; Quote Link to comment Share on other sites More sharing options...
Shocker88 Posted October 7, 2009 Share Posted October 7, 2009 Did implementing the suggested statement fix your problem mate? Quote Link to comment Share on other sites More sharing options...
onthespot Posted October 7, 2009 Author Share Posted October 7, 2009 <? $archive2="SELECT comp FROM confirmedresults WHERE home_user = '$suser' OR away_user = '$suser'"; $archq2=mysql_query($archive2); while($row=mysql_fetch_assoc($archq2)){ $comp_name2=$row['comp']; } $archive="SELECT * FROM archive WHERE comp_name = '$comp_name2' "; $archq=mysql_query($archive); $num_rows = mysql_num_rows($archq); echo $num_rows; if ($num_rows > 0) { ?> <table cellspacing="10"> <tr> <td>Competition Name</td> <td>Game</td> <td>Format</td> </tr> <? while($row=mysql_fetch_assoc($archq)){ $comp_name=$row['comp_name']; $comp_game=$row['game']; $comp_format=$row['format']; { extract($row); $info = explode("_",$row[comp_name]); ?> <tr> <td><a href="league.php?comp=<? echo $comp_name ?>"><? echo $info[2]; ?></a></td> <td><? echo $comp_game; ?></td> <td><? echo $comp_format; ?></td> </tr> <? } } ?> </table> <? } else { echo "$suser doesn't currently have any archived competitions"; } ?> How can i make the join work on that? I tried and i got no results at all, not even any rows, didnt even echo 0 rows when i tried! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.