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! Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/ 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> Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744045 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? Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744049 Share on other sites More sharing options...
dezkit Posted January 23, 2009 Author Share Posted January 23, 2009 SQL table!!! Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744050 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. Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744052 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? >.> Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744060 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, Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744064 Share on other sites More sharing options...
dezkit Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks uni Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744067 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/142077-solved-make-results-vertical-not-horizantal/#findComment-744070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.