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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/ 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? Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342255 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342286 Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 Quote 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 https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342287 Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 I misunderstood but I edited my reply Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342290 Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 Quote 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342293 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 Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342294 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342295 Share on other sites More sharing options...
McMaster Posted May 2, 2012 Share Posted May 2, 2012 Quote Quote 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342296 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342297 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. Link to comment https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342299 Share on other sites More sharing options...
Mahngiel Posted May 2, 2012 Share Posted May 2, 2012 Quote 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 https://forums.phpfreaks.com/topic/261946-tables-side-by-side/#findComment-1342328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.