Jump to content

[SOLVED] Make results Vertical Not Horizantal


dezkit

Recommended Posts

<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
Share on other sites

*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
Share on other sites

ah thats better :P, 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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.