harleyridin Posted March 8, 2009 Share Posted March 8, 2009 I have searched exhaustively and not found what I need. Here is my situation. I need to display mysql data with each field on a separate row. I am currently using a mysql database (version 5.0.75-community-log) with the table (attendees) and fields: name, email, age, date. I use the following to retrieve and display the data: ... $result = mysql_query("SELECT * FROM attendees order by date"); echo "<table border='1'> <tr> <th>Name</th> <th>Email</th> <th>Age</th> <th>Date</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['age'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "</tr>"; } echo "</table>"; //mysql_close($con); ?> This displays all the records in columns like this: Name Email Age Date data data data data data data data data I am going to change my query so I only display one record and I need to have it displayed as: Name: data Email: data Age: data Date: data Link to comment https://forums.phpfreaks.com/topic/148491-display-each-field-in-mysql-table-in-separate-rows/ Share on other sites More sharing options...
Flames Posted March 8, 2009 Share Posted March 8, 2009 ... $result = mysql_query("SELECT * FROM attendees order by date"); echo "<table border='1'> <tr> <th>Name</th> <th>Email</th> <th>Age</th> <th>Date</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<table border='1'> <tr><th>Name</th><td>".$row['name']."</td></tr> <tr><th>Email</th><td>".$row['email']."</td></tr> <tr><th>Age</th><td>".$row['age']."</td></tr> <tr><th>Date</th><td>".$row['date."</td></tr> </table>"; } //mysql_close($con); ?> It will work if you only select one piece of data. Link to comment https://forums.phpfreaks.com/topic/148491-display-each-field-in-mysql-table-in-separate-rows/#findComment-779844 Share on other sites More sharing options...
harleyridin Posted March 8, 2009 Author Share Posted March 8, 2009 I really appreciate your response. I changed my query to select one record and put the new code in. I got the following error message: Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/bigcross/public_html/dbcheck.php on line 30 Parse error: syntax error, unexpected ';', expecting ']' in /home/bigcross/public_html/dbcheck.php on line 31 Link to comment https://forums.phpfreaks.com/topic/148491-display-each-field-in-mysql-table-in-separate-rows/#findComment-779869 Share on other sites More sharing options...
Mundo Posted March 8, 2009 Share Posted March 8, 2009 You only want one result? Just remove the while loop. You could also add a limit to your query: $result = mysql_query("SELECT * FROM attendees order by date LIMIT 0, 1"); Link to comment https://forums.phpfreaks.com/topic/148491-display-each-field-in-mysql-table-in-separate-rows/#findComment-779873 Share on other sites More sharing options...
harleyridin Posted March 8, 2009 Author Share Posted March 8, 2009 Thanks for the help. I'm going to get to work on this and see what I come up with. Once again...thanks Link to comment https://forums.phpfreaks.com/topic/148491-display-each-field-in-mysql-table-in-separate-rows/#findComment-779880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.