sirenia Posted September 22, 2008 Share Posted September 22, 2008 I accidentally screwed up the coding for my site and where it used to be that I had two MySQL entries displayed side by side in tables, I now have one by one. <? php if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } echo"<table border=\"0\" cellspacing=\"1\" cellspacing=\"2\" width=\"210\"> <tr><td><img src=\"$preview\"><br> <b>ID:</b> $id<br> <b>Series:</b> $series<br> <b>Artist:</b> $artist<br> </td>\n"; $numcolsprinted++; } $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<td></td>\n"; echo"</tr><br>"; echo"<tr><td align=\"center\">"; ?> That might be the root of the problem, and I tried http://www.phpfreaks.com/forums/index.php/topic,172369.0.html but that didn't help much. Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/ Share on other sites More sharing options...
F1Fan Posted September 23, 2008 Share Posted September 23, 2008 Is there more to this code? And when you refer to "tables," do you mean DB tables or HTML tables? Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/#findComment-648257 Share on other sites More sharing options...
chronister Posted September 23, 2008 Share Posted September 23, 2008 http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Here is a "tutorial/snippet" for accomplishing this. Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/#findComment-648262 Share on other sites More sharing options...
sirenia Posted September 23, 2008 Author Share Posted September 23, 2008 F1, yes there is but I thought that was the only relevant part. By tables I mean like <table><tr><td> displaying 2 beside each other and listing them like that. chronister, I tried that link already and it displayed my tables twice. I'm not too good with PHP. The full code is: <?php $query = "select * from wallp order by id desc"; $result=mysql_query($query); $numcols = 2; $numcolsprinted = 0; $rows_per_page=4; $total_records=mysql_num_rows($result); $pages = ceil($total_records / $rows_per_page); mysql_free_result($result); if (!isset($screen)) $screen=0; $screen = $_GET['screen']; $start = $screen * $rows_per_page; $query .= " LIMIT $start, $rows_per_page"; $result2 = mysql_query($query); while ($row=mysql_fetch_array($result2)) { $id=$row["id"]; $twelve=$row["twelve"]; $ten=$row["ten"]; $eight=$row["eight"]; $artist=$row["artist"]; $type=$row["type"]; $series=$row["series"]; $preview=$row["preview"]; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } echo"<table border=\"0\" cellspacing=\"1\" cellspacing=\"2\" width=\"210\"> <tr><td class=\"temp\"><img src=\"$preview\"><br> <b>ID:</b> $id<br> <b>Series:</b> $series<br> <b>Artist:</b> $artist<br> </td>\n"; $numcolsprinted++; } $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<td></td>\n"; echo"</tr><br>"; echo"<tr><td align=\"center\">"; if ($screen > 0) { $j = $screen - 1; $url = "$PHP_SELF?series=$series&screen=$j"; echo "<a href=\"$url\">« Prev.</a>"; } // page numbering links now $p = 5; $lower = $p; $upper = $screen+$p; while($upper>$pages){ $p = $p-1; $upper = $screen+$p; } if($p<$lower){ $y = $lower-$p; $to = $screen-$y; while($to<0){ $to++; } } if(!empty($to)) { for ($i=$to;$i<$screen;$i++){ $url = "$PHP_SELF?series=$series&screen=" . $i; $j = $i + 1; echo " | <a href=\"$url\">$j</a> | "; } } for ($i=$screen;$i<$upper;$i++) { $url = "$PHP_SELF?series=$screen=" . $i; $j = $i + 1; echo " | <a href=\"$url\">$j</a> "; } if ($screen < $pages-1) { $j = $screen + 1; $url = "$PHP_SELF?series=$series&screen=$j"; echo "<a href=\"$url\">Next »</a>"; } echo"</td></tr>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/#findComment-648674 Share on other sites More sharing options...
sasa Posted September 23, 2008 Share Posted September 23, 2008 try <?php ... // start table echo "<table border=\"0\" cellspacing=\"1\" cellspacing=\"2\" width=\"210\">"; while ($row=mysql_fetch_array($result2)) { $id=$row["id"]; $twelve=$row["twelve"]; $ten=$row["ten"]; $eight=$row["eight"]; $artist=$row["artist"]; $type=$row["type"]; $series=$row["series"]; $preview=$row["preview"]; if ($numcolsprinted == 0) print "<tr>\n"; echo "<td class=\"temp\"><img src=\"$preview\"><br> <b>ID:</b> $id<br> <b>Series:</b> $series<br> <b>Artist:</b> $artist<br> </td>\n"; $numcolsprinted++; if ($numcolsprinted == $numcols) { echo "</tr>\n"; $numcolsprinted = 0; } } if ($numcolsprinted > 0){ for (; $numcolsprinted <= $numcols; $numcolsprinted++) echo "<td> </td>\n"; echo "</tr>\n"; } echo "</table>\n"; ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/#findComment-648804 Share on other sites More sharing options...
sirenia Posted September 23, 2008 Author Share Posted September 23, 2008 Thank you, it works. Quote Link to comment https://forums.phpfreaks.com/topic/125383-solved-getting-2-table-rows-beside-each-other/#findComment-649056 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.