ncncnc Posted May 2, 2012 Share Posted May 2, 2012 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. Quote Link to comment Share on other sites More sharing options...
yami007 Posted May 2, 2012 Share Posted May 2, 2012 Why didnt you use float:left on the first table? Quote Link to comment Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 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? Quote Link to comment Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 I misunderstood but I edited my reply Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 I misunderstood but I edited my reply 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. Quote Link to comment Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 <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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 So, you'd hack it. OP, set both tables to float: left and use a br or div with clear:both after them. Quote Link to comment Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 I misunderstood but I edited my reply 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 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. Quote Link to comment Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 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. Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted May 2, 2012 Share Posted May 2, 2012 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... 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.