superhoops Posted August 28, 2006 Share Posted August 28, 2006 [code]I know this might be a really simple answer but i am going to work on using this example for what i need to do which is select the data from my database and put it onto a html table.Here is some of the code from the tutorial i am using:[code}<?echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . echo $row['FirstName'] . "</td>"; echo "<td>" . echo $row['LastName'] . "</td>"; echo "</tr>"; }echo "</table>";?>[/code]My first question is, is the echo before every part of the table nessary? Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Just a yes or no answer required guys. Im a newbie sorry. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 [quote]My first question is, is the echo before every part of the table nessary?[/quote]What do you mean before every part of the table?This will do the same thing:[code]<?phpecho " <table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> </tr>";while($row = mysql_fetch_array($result)) { echo " <tr> <td>" . echo $row['FirstName'] . "</td> <td>" . echo $row['LastName'] . "</td> </tr>";}echo "</table>";?>[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Ok I now get this error:[b]Parse error: syntax error, unexpected '<' in /home/www/fmprotasy.com/Test/tranmark2main.php on line 14[/b]Here is the code i have:[code]<?mysql_select_db("fmprotasy_reg", $con);$result = mysql_query("SELECT * FROM Market");<table border="0" bgcolor="#FF8C00" width="100%" cellpadding="10"><tr><td width="100%" valign="top" style="border-style: solid; border-width: 2"><p align="left"><b><font face="Arial" size="2">Transfer Market</font></b></td></tr></table><table border="0" bgcolor="#FF8C00" width="100%" cellpadding="10" height="15"><tr><td width="100%" valign="top" height="1" style="border-style: solid; border-width: 2">echo "<table border='1'><tr><th>Player</th><th>Club</th><th>Position</th><th>Age</th><th>Ka</th><th>Ta</th><th>Pa</th><th>Sa</th><th>Type</th><th>Price</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Player'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Team'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Position'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Age'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['GK'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['DEF'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['MID'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['ATT'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Type'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Price'] . "</font></td>"; echo "</tr>"; }echo "</table>";</td></tr></table>mysql_close($con);?>[/code]Im sure there is loads of mistakes but if anyone could identify the problem for me i would be very greatful, thanks. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 You need to escape the double quotes in your echo statements if you are going to enclose them in double quotes.You aren't echoing out the html that is inside of the php. For example:[code]echo "</table>";</td></tr></table>[/code]Should be, at a minimum like this:[code]echo "</table></td></tr></table>";[/code]this should work overall:[code]<?phpmysql_select_db("fmprotasy_reg", $con);$result = mysql_query("SELECT * FROM Market");echo '<table border="0" bgcolor="#FF8C00" width="100%" cellpadding="10"> <tr> <td width="100%" valign="top" style="border-style: solid; border-width: 2"> <p align="left"><b><font face="Arial" size="2">Transfer Market</font></b> </td> </tr></table><table border="0" bgcolor="#FF8C00" width="100%" cellpadding="10" height="15"> <tr> <td width="100%" valign="top" height="1" style="border-style: solid; border-width: 2"> <table border='1'> <tr> <th>Player</th> <th>Club</th> <th>Position</th> <th>Age</th> <th>Ka</th> <th>Ta</th> <th>Pa</th> <th>Sa</th> <th>Type</th> <th>Price</th> </tr>';while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Player'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Team'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Position'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Age'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['GK'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['DEF'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['MID'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['ATT'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Type'] . "</font></td>"; echo "<td align="center"><font face="Arial" size="2">" . echo $row['Price'] . "</font></td>"; echo "</tr>";}echo " </table> </td> </tr></table>";mysql_close($con);?>[/code]Please read a tutorial on basic php syntax, which will solve 95% of the problems you experience.http://www.w3schools.com/php/default.asp Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Thank You for that and i will read up properly on PHP Syntax. Unfortunately i now get this error:[b]Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in /home/www/fmprotasy.com/Test/tranmark2main.php on line 25[/b]I have looked at line 25 and the line before it and i can't see the error but im sure it is very simple.Sorry Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 [quote]You need to escape the double quotes in your echo statements if you are going to enclose them in double quotes.[/quote][code]echo "<td align="center"><font face="Arial" size="2">" . echo $row['Player'] . "</font></td>";[/code]should be"[code]echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Player'] . "</font></td>";[/code]All of the other echo statements should be the same way...you have to escape them.Same holds true for this line:[code]<table border='1'>[/code]Because it's in an echo statment that encloses the echoed text in single quotes, they must be escaped or they will cause an error.[code]<table border=\'1\'>[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Ive done what you said and put \ before every "I now get this error:[b]Parse error: syntax error, unexpected T_ECHO in /home/www/fmprotasy.com/Test/tranmark2main.php on line 40[/b]Here is the code of my script:[code]<?php$db = mysql_connect("db5.awardspace.com:3306", "fmpsite_reg", "password") or die("Could not connect.");if(!$db) die("no db");if(!mysql_select_db("fmpsite_reg",$db)) die("No database selected.");if(!get_magic_quotes_gpc())?><?phpmysql_select_db("fmprotasy_reg", $con);$result = mysql_query("SELECT * FROM Market");echo '<table border=\"0\" bgcolor=\"#FF8C00\" width=\"100%\" cellpadding=\"10\"> <tr> <td width=\"100%\" valign=\"top\" style=\"border-style: solid; border-width: 2\"> <p align=\"left\"><b><font face=\"Arial\" size="2">Transfer Market</font></b> </td> </tr></table><table border="0" bgcolor=\"#FF8C00\" width=\"100%\" cellpadding=\"10\" height=\"15\"> <tr> <td width=\"100%\" valign=\"top\" height=\"1\" style=\"border-style: solid; border-width: 2\"> <table border=\"1\"> <tr> <th>Player</th> <th>Club</th> <th>Position</th> <th>Age</th> <th>Ka</th> <th>Ta</th> <th>Pa</th> <th>Sa</th> <th>Type</th> <th>Price</th> </tr>';while($row = mysql_fetch_array($result)) { echo "<tr>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Player'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Team'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Position'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Age'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['GK'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['DEF'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['MID'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['ATT'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Type'] . "</font></td>";echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Price'] . "</font></td>"; echo "</tr>";}echo " </table> </td> </tr></table>";mysql_close($con);?>[/code]What do i need to do now? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 I must not be paying attention today.....change:[code]echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . echo $row['Player'] . "</font></td>";[/code]to:[code]echo "<td align=\"center\"><font face=\"Arial\" size=\"2\">" . $row['Player'] . "</font></td>";[/code]In all of the other, equivalent, statements as well. Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Thanks, its getting better. I now get 2 more errors. here is the web linkhttp://www.fmprotasy.com/Test/transfer_market2.php Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 28, 2006 Share Posted August 28, 2006 change:[code]$result = mysql_query("SELECT * FROM Market");[/code]to:[code]$result = mysql_query("SELECT * FROM Market") or die(mysql_error());[/code]to see what the error is. Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Ive done that but there is still no difference. Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Hitman do you know what to do? Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted August 28, 2006 Share Posted August 28, 2006 Something didnt look right so I copied and pasted your code made a database, debugged different errors and this worked:[code]<?phpmysql_select_db('fmprotasy_reg', $con);$result = mysql_query('SELECT * FROM Market');echo '<table border=0 bgcolor=#FF8C00 width=100% cellpadding=10> <tr> <td width=100% valign=top style=border-style: solid; border-width: 2> <p align=left><b><font face=Arial size=2>Transfer Market</font></b> </td> </tr></table><table border=0 bgcolor=#FF8C00 width=100% cellpadding=10 height=15> <tr> <td width=100% valign=top height=1 style=border-style: solid; border-width: 2> <table border=1> <tr> <th>Player</th> <th>Club</th> <th>Position</th> <th>Age</th> <th>Ka</th> <th>Ta</th> <th>Pa</th> <th>Sa</th> <th>Type</th> <th>Price</th> </tr>';while($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td align=center><font face=Arial size=2>' . $row['Player'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['Team'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['Position'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['Age'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['GK'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['DEF'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['MID'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['ATT'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['Type'] . '</font></td>'; echo '<td align=center><font face=Arial size=2>' . $row['Price'] . '</font></td>'; echo '</tr>';}echo ' </table> </td> </tr></table>';mysql_close($con);?>[/code] Quote Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Author Share Posted August 28, 2006 Hitman i sorted the problem, it was very simple in the end.Thank You so much for all the help you have given me. I really appreicate it. 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.