JBuss1503 Posted March 17, 2014 Share Posted March 17, 2014 Hi all, I was wondering if you can help me with an issue I am having with my website. I am very new to php/html/css and mysql so I know very little. I have an order form on my website which when filled in send data to my database. I then have an admin page on my site which shows the data in the database. However, I need the data to be stored in a table with a row containing the column name and then each row showing the actual data underneath. Would like it in a grid sort of format. My current code is: <!doctype html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <link href="css/reset.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container2"> <div id="adminpanel"> Admin Page <div id="showorders"><u>Orders</u></div> <?php include('connection.php'); $result = mysql_query("SELECT * FROM orderform"); while($row = mysql_fetch_array($result)) { echo "<span style='color: #333; width: 200px; height: 200px; padding: 1px; border: 1px solid #ff9900;'>" . $row['product'] . " " . $row['productcomments'] . " " . $row['name'] . " " . $row['address'] . " " . $row['age'] . " " . $row['delivery'] . "</span>" ; echo "<br>"; } ?> <div id="showreviews"><u>Reviews</u></div> <?php $result = mysql_query("SELECT * FROM reviewform"); while($row = mysql_fetch_array($result)) { echo "<span style='color: #333; width: 200px; height: 200px; padding: 5px; border: 1px solid #ff9900;'>" . $row['name'] . " " . $row['product'] . " " . $row['comment'] . "</span>" ; echo "<br>"; echo $row['name'] . " " . $row['product'] . " " . $row['comment'] ; echo "<br>"; } ?> </div> </div> </body> This code puts a border around each row but doesnt seperate each column and doesnt show a header. Ultimately, I am going to want to sort each order by different criteria e.g alphabetical, date ordered, product type.All help is really appreciated as I am really pushed for time and a complete beginner. Thanks Jonathan Link to comment https://forums.phpfreaks.com/topic/287028-displaying-data-from-mysql-in-a-table-on-html-page/ Share on other sites More sharing options...
Ch0cu3r Posted March 17, 2014 Share Posted March 17, 2014 Sounds like what you want is a HTML table. The basic code for a table is <table> <tr> <th>Heading 1</th> <th>Heading 2</th> etc... </tr> <tr> <td>Column 1</td> <td>Column 2</td> etc... <tr> <tr> etc. </tr> </tablel> So the column headings go between <th> and </th>, each row is echoed between <tr> and </tr> and each column value is echo'd between <td> and </td>. The following with output the results from your orderform query into a HTML table <div id="showorders"><u>Orders</u></div> <table border="1" cellpadding="4"> <!-- start the table, defining the table column headings --> <tr> <th>Product</th> <th>Comments</th> <th>Name</th> <th>Address</th> <th>Age</th> <th>Delivery</th> </tr> <?php include('connection.php'); $result = mysql_query("SELECT * FROM orderform"); while($row = mysql_fetch_array($result)) { // each row returned from the query echo into individual columns for the table echo ' <tr> <td>'.$row['product'].'</td> <td>'.$row['productcomments'].'</td> <td>'.$row['name'].'</td> <td>'.$row['address'].'</td> <td>'.$row['age'].'</td> <td>'.$row['delivery'].'</td> </tr>'; } ?> </table> <!-- end table --> Link to comment https://forums.phpfreaks.com/topic/287028-displaying-data-from-mysql-in-a-table-on-html-page/#findComment-1472881 Share on other sites More sharing options...
JBuss1503 Posted March 17, 2014 Author Share Posted March 17, 2014 Thanks I have done that and it has arranged into a table. Is there a way I can style the headings and the data within the headings (centre all of the text within the grid for example)? Many Thanks Link to comment https://forums.phpfreaks.com/topic/287028-displaying-data-from-mysql-in-a-table-on-html-page/#findComment-1472885 Share on other sites More sharing options...
ginerjm Posted March 17, 2014 Share Posted March 17, 2014 Read up on CSS for styling tips. A simple <center> tag preceding the table defn will center all data in each cell if that's all you want. Link to comment https://forums.phpfreaks.com/topic/287028-displaying-data-from-mysql-in-a-table-on-html-page/#findComment-1472889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.