FedEx11 Posted September 25, 2009 Share Posted September 25, 2009 I have this <body background = "bg.jpg"> <?php $con = mysql_connect("localhost","root",""); //or die(mysql_error()); mysql_select_db('tennis',$con); //or die(mysql_error()); $result = mysql_query("SELECT p1.player_name as 'Player1', p2.player_name as 'Player2', m.Result as 'Result', m.Score as 'Score', m.Location as 'Location', m.Date as 'Date' from matches m , players p1, players p2 WHERE p1.ID = m.Player1_ID and p2.ID = m.Player2_ID order by m.Date desc "); if (!$result) { die(mysql_error()); } while ($row = mysql_fetch_assoc($result)) { print_r($row); } mysql_close($con); The problems is the result is showing like this : Array ( [Player1] => John Doe [Player2] => Jason Doe [Result] => D [score] => 6/4 5/7 [Location] => PAris [Date] => 2009-09-17 ) Array ( [Player1] => John Doe [Player2] => Micheal Doe [Result] => W [score] => 6/2 6/1 [Location] => London [Date] => 2009-09-15 ) Any idea what im doing wrong ? Link to comment https://forums.phpfreaks.com/topic/175556-solved-php-code-sql-results/ Share on other sites More sharing options...
p2grace Posted September 25, 2009 Share Posted September 25, 2009 print_r() displays the results of an array, which is why it's displaying like that. If you want to display in a table you'll need to loop through the results and construct the html. Link to comment https://forums.phpfreaks.com/topic/175556-solved-php-code-sql-results/#findComment-925083 Share on other sites More sharing options...
monkeytooth Posted September 25, 2009 Share Posted September 25, 2009 Your printing out the array itself with the print_r($row); try: echo $row['Player1']; echo $row['Player2']; echo $row['Result']; echo $row['Score']; echo $row['Location']; echo $row['Date']; Link to comment https://forums.phpfreaks.com/topic/175556-solved-php-code-sql-results/#findComment-925084 Share on other sites More sharing options...
mrgenericuser Posted September 25, 2009 Share Posted September 25, 2009 echo "<table>"; while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; foreach($row as $data){ echo "<td>".$data."</td>"; } echo "</tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/175556-solved-php-code-sql-results/#findComment-925098 Share on other sites More sharing options...
FedEx11 Posted September 26, 2009 Author Share Posted September 26, 2009 Thanks a lot all! Link to comment https://forums.phpfreaks.com/topic/175556-solved-php-code-sql-results/#findComment-925336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.