dezkit Posted January 23, 2009 Share Posted January 23, 2009 I have a table with like 6 rows and I want the layout to be selected like this: Name: --- Date: --- Description: --- Image: --- Instead of Name Date Description Image --- --- --- --- How do I achieve this? Thank you! Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 23, 2009 Share Posted January 23, 2009 <table border=0 cellpadding=8> <tr> <td>Name:</td> <td>--</td> </tr> <tr> <td>Date:</td> <td>--</td> </tr> <tr> <td>Description:</td> <td>--</td> </tr> <tr> <td>Image:</td> <td>--</td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
N1CK3RS0N Posted January 23, 2009 Share Posted January 23, 2009 HTML? or displaying results from a SQL table? Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 23, 2009 Author Share Posted January 23, 2009 SQL table!!! Quote Link to comment Share on other sites More sharing options...
uniflare Posted January 23, 2009 Share Posted January 23, 2009 <table border=0 cellpadding=8> <tr> <td>Name:</td> <td>--</td> </tr> <tr> <td>Date:</td> <td>--</td> </tr> <tr> <td>Description:</td> <td>--</td> </tr> <tr> <td>Image:</td> <td>--</td> </tr> </table> This is your answer, it is a html table that will display a vertical structure. Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 23, 2009 Author Share Posted January 23, 2009 *Clears throat* This is horizantal: <?php // Make a MySQL Connection mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM example") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; ?> How do I make it vertical? >.> Quote Link to comment Share on other sites More sharing options...
uniflare Posted January 23, 2009 Share Posted January 23, 2009 ah thats better , some code . You must change this part: <?php echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['name']; echo "</td><td>"; echo $row['age']; echo "</td></tr>"; } echo "</table>"; ?> This gives you a table row with 2 columns for each result, you want 2 table rows with 2 columns each, so you should modify: <?php echo "<table border='1'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>Name:</td> <td>".$row['name']."</td></tr>"; echo "<tr><td>Age:</td> <td>".$row['age']."</td></tr>"; } echo "</table>"; ?> Something like this? Hope this helps, Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks uni Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 23, 2009 Share Posted January 23, 2009 Or do you want them displayed like this? | Name: | Name1 | Name2 | Name3 | | Date: | Date1 | Date2 | Date3 | | Description: | Descr1 | Descr2 | Descr3 | | Image: | Image1 | Image2 | Image3 | <?php //Query the DB $query = "SELECT * FROM table"; $result = mysql_query($query) or die(mysql_error()); //Populate results into an array while($row = mysql_fetch_assoc($result)) { $result_ary['Name'][] = $row['name']; $result_ary['Date'][] = $row['date']; $result_ary['Description'][] = $row['description']; $result_ary['Image'][] = $row['image']; } //Populate table horizontally echo "<table border='1'>\n"; foreach($result_ary as $field_name => $field_values) { echo "<tr>\n"; echo "<th>{$field_name}</th>"; foreach($field_values as $value) { echo "<td>{$value}</td>"; } echo "</tr>\n"; } echo "</table>"; ?> 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.