Jump to content

Tables side by side


ncncnc

Recommended Posts

Hi all,

 

I've made a webpage that displays data taken from SQL. I'm trying to display two seperatre tables side by sie. I can currently display them side by side but one is below and to the side of the other. I wan't them right next to each other. Can somebody help?

 

  echo '<table border="1" BORDERCOLOR=Black style=width:300px >';

echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue">Sales Volume</th><th bgcolor = "LightBlue">Year</th></tr>';



while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) 
{
    echo '<tr>';
echo '<td >' .$row['NAME'].'</td>'; 
echo '<td>' .$row['SalesVolume'].'</td>'; 
echo '<td>' .$row['Year'].'</td>'; 
echo '</tr>';


} 

echo '</table>';



echo '<table border="2" BORDERCOLOR=Black style=float:left;margin-left:400px; width:300px>';
echo '<tr><th bgcolor = "Black">ID</th><th bgcolor = "Black" >Name</th> <th bgcolor = "Black" >Price</th></tr>';


while($row = sqlsrv_fetch_array($results2, SQLSRV_FETCH_ASSOC)) 
  {   
    echo '<tr>';
echo '<td >' .$row['ID'].'</td>'; 
echo '<td>' .$row['Name'].'</td>'; 
echo '<td>£' .$row['Price'].'</td>'; 	
echo '</tr>';
} 

echo '</table>';


sqlsrv_close($conn);

?>


 

I've been trying to position the table using margins.

Link to comment
Share on other sites

float:left isn't necessary. If I understand you correctly, add a cellpadding="0" and cellspacing="0" to the table. You may also need to use an inline style for the margin... style="margin:0"

How would you get two block elements to appear side by side without float?

Link to comment
Share on other sites

I misunderstood but I edited my reply :P

Your new response makes even less sense, especially since I'm pretty sure the OP isn't using MySQL, and this is a topic about html/css not sql.

Link to comment
Share on other sites

<table>
<tr>
<td>
<!-- THIS IS TABLE 1 (LEFT) -->
<table border="1" BORDERCOLOR=Black style=width:300px >';
<tr>
<th bgcolor = "LightBlue">Name</th>
<th bgcolor = "LightBlue">Sales Volume</th>
<th bgcolor = "LightBlue">Year</th></tr>';
</tr>
<?php
while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) 
{
    echo '<tr>';
echo '<td >' .$row['NAME'].'</td>'; 
echo '<td>' .$row['SalesVolume'].'</td>'; 
echo '<td>' .$row['Year'].'</td>'; 
echo '</tr>';


}
?>
</table>
</td>
<td>
<!-- THIS IS TABLE 2 (RIGHT) -->
<table border="1" BORDERCOLOR=Black style=width:300px >';
<tr>
<th bgcolor = "LightBlue">Name</th>
<th bgcolor = "LightBlue">Sales Volume</th>
<th bgcolor = "LightBlue">Year</th></tr>';
</tr>
<?php
while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) 
{
    echo '<tr>';
echo '<td >' .$row['NAME'].'</td>'; 
echo '<td>' .$row['SalesVolume'].'</td>'; 
echo '<td>' .$row['Year'].'</td>'; 
echo '</tr>';


}
?>
</table>
</td></tr>
</table>

 

Notice how I put 2 tables in 1 so now you have a left and right column. No float:left ;)

Link to comment
Share on other sites

I misunderstood but I edited my reply :P

Your new response makes even less sense, especially since I'm pretty sure the OP isn't using MySQL, and this is a topic about html/css not sql.

 

The user is reading records from the sql database to feed the table... check their original code.

Link to comment
Share on other sites

You said "Why not put a MySQL LIMIT on the first table and then another LIMIT on the second? You will also need to put both tables in 1 separate table."

 

You do know that MySQL is not the only database there is right? I would love to see how you use sqlsrv_fetch_array to get rows from a MySQL database.

 

I think you're confusing a database table with an html table. This question has NOTHING to do with LIMIT or their queries, and everything to do with positioning two HTML elements. If the OP comes back and says the problem was too many results, your response might have some merit. But as it is, this question is pertaining to positioning two HTML tables, not getting the results out of the database table.

 

Nesting tables is a bad practice. Tables are for tabular data. CSS is for positioning. EOM.

Link to comment
Share on other sites

It clearly says in the original users post "I've made a webpage that displays data taken from SQL" .. maybe MySQL/MSSQL who knows but I am pretty sure they got the idea of what I was saying. Nesting tables is not bad practice at all although it can be tricky if you nest a lot as there will be a lot of code. A nested table can position just as good as CSS so wherever you got the idea of CSS is for positioning and not tables is a lot of crap lol.

Link to comment
Share on other sites

Nesting tables is not bad practice at all although it can be tricky if you nest a lot as there will be a lot of code. A nested table can position just as good as CSS so wherever you got the idea of CSS is for positioning and not tables is a lot of crap lol.

 

It's thought processes like this (and the use of IE6) that holds the internet back in 1990.  Just no.  Next thing you'll say will be to use <b> for bold...

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.