skidmark10 Posted August 15, 2011 Share Posted August 15, 2011 Hello, I am trying to retrieve and display data from a mysql table into a html table using php. I am using this code and it works successfully. <?php mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'> <tr> <th>Firstname</th> <th>Lastname</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> However, I want $row['FirstName'] and $row['LastName'] to appear in the SAME cell of the html table, next to one another. How would I write the code for that, if it is possible Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/ Share on other sites More sharing options...
jcbones Posted August 15, 2011 Share Posted August 15, 2011 mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']"</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1257853 Share on other sites More sharing options...
skidmark10 Posted August 15, 2011 Author Share Posted August 15, 2011 Quote mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']"</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I don't think that works, I keep receiving the same error as before :-\ Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1257864 Share on other sites More sharing options...
jcbones Posted August 15, 2011 Share Posted August 15, 2011 No where in your first post did you say anything about a parse error! Post your ENTIRE script, that is the only way to deal with parse errors. (Include the acutal error also, there should be a line number in it.) Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1257874 Share on other sites More sharing options...
skidmark10 Posted August 16, 2011 Author Share Posted August 16, 2011 Quote No where in your first post did you say anything about a parse error! Post your ENTIRE script, that is the only way to deal with parse errors. (Include the acutal error also, there should be a line number in it.) I tried a similar code (not the code I posted) I put this and got a parse error echo "<td>" . $row['FirstName'] . " . $row['LastName']"</td>" ; Then I tried your code too and received a parse error echo "<td>" . $row['FirstName'] . ' ' . $row['Last_Name']"</td>"; Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1257958 Share on other sites More sharing options...
phpSensei Posted August 16, 2011 Share Posted August 16, 2011 this line . $row['LastName']"</td>"; Is missing a '.' try <?php mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1257965 Share on other sites More sharing options...
jcbones Posted August 16, 2011 Share Posted August 16, 2011 Quote this line . $row['LastName']"</td>"; Is missing a '.' try <?php mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I apologize for that, I'm gonna have to get more sleep, and quit being mean to people! Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1258309 Share on other sites More sharing options...
phpSensei Posted August 16, 2011 Share Posted August 16, 2011 I was being mean to people? Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1258317 Share on other sites More sharing options...
skidmark10 Posted August 17, 2011 Author Share Posted August 17, 2011 Quote Quote this line . $row['LastName']"</td>"; Is missing a '.' try <?php mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Name</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . ' ' . $row['LastName']. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I apologize for that, I'm gonna have to get more sleep, and quit being mean to people! Thank you so much! Link to comment https://forums.phpfreaks.com/topic/244862-select-mysql-display-in-an-html-table-using-php/#findComment-1258368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.