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 Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted March 17, 2014 Solution Share Posted March 17, 2014 (edited) 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 --> Edited March 17, 2014 by Ch0cu3r Quote Link to comment 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 Quote Link to comment 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. 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.