dessolator Posted December 5, 2007 Share Posted December 5, 2007 Hi, I', having trouble with this if statement and I can't see why, it displays 'no results' like its supposed to but it goes in a new column instead of a new row. This is the code for that if statement: if ($row[0] AND $row[1] == 0){ echo "<td bgcolor='#CCCCCC' align='center'>No results</td>"; } This is what the table looks like with the no results out of place: PlayerY PlayerG Game ScoreY ScoreG Winner Albert Charles Cribbage 3 0 Yellow No results Albert Denise Spillikins 2 1 Yellow Aswan Charles Snap 1 2 Green Debra Bertha Junior Scrabble 0 0 This is the full code: <?php ob_start(); $host="localhost"; // Host name $dbusername="root"; // Mysql username $password="abc123"; // Mysql password $db_name="games_db1"; // Database name $tbl_name="members"; // Table name //Getting house and class for SECOND user from db and storing it in variables mysql_connect("$host", "$dbusername", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Database - Assigns the below statement into the variable query $query = "SELECT results.ScoreY, results.ScoreG, results.Game, results.GameID, results.PlayerY, members.Forename AS PlayerYname, results.PlayerG, members_1.Forename AS PlayerGname FROM members AS members_1 RIGHT JOIN ( members RIGHT JOIN results ON members.id = results.PlayerY ) ON members_1.id = results.PlayerG LIMIT 0 , 30;"; $result = mysql_query($query) or die (mysql_error()); //print_r($result); //$row = mysql_fetch_row($result); echo '<table border=0 align="center"> <tr> <th align="center" bgcolor="orange">PlayerY</th> <th align="center" bgcolor="orange">PlayerG</th> <th align="center" bgcolor="orange">Game</th> <th align="center" bgcolor="orange">ScoreY</th> <th align="center" bgcolor="orange">ScoreG</th> <th align="center" bgcolor="orange">Winner</th> </tr>'; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td bgcolor='#CCCCCC' align='center'>".$row[5] . " "."</td>"; echo "<td bgcolor='#CCCCCC' align='center'>".$row[7] . " "."</td>"; echo "<td bgcolor='#CCCCCC' align='center'>".$row[2] . " "."</td>"; echo "<td bgcolor='#CCCCCC' align='center'>".$row[0] . " "."</td>"; echo "<td bgcolor='#CCCCCC' align='center'>".$row[1] . " "."</td>"; if ($row[0] > $row[1]){ echo "<td bgcolor='#CCCCCC' align='center'>Yellow</td>"; } if ($row[0] < $row[1]){ echo "<td bgcolor='#CCCCCC' align='center'>Green</td>"; } if ($row[0] AND $row[1] == 0){ echo "<td bgcolor='#CCCCCC' align='center'>No results</td>"; } } echo "</center>"; ?> I would really appreciate it if you could take a look for me. Thanks, Ian Link to comment https://forums.phpfreaks.com/topic/80357-solved-if-statement-trouble/ Share on other sites More sharing options...
micah1701 Posted December 5, 2007 Share Posted December 5, 2007 nevermind. Link to comment https://forums.phpfreaks.com/topic/80357-solved-if-statement-trouble/#findComment-407294 Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Where is your close for echo "<tr>"; Also, TD will not start a new Row, TR will. Link to comment https://forums.phpfreaks.com/topic/80357-solved-if-statement-trouble/#findComment-407298 Share on other sites More sharing options...
dessolator Posted December 5, 2007 Author Share Posted December 5, 2007 Thanks a lot for your help sorted it now. Link to comment https://forums.phpfreaks.com/topic/80357-solved-if-statement-trouble/#findComment-407333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.