Jump to content

[SOLVED] Getting 2 table 'rows' beside each other


Recommended Posts

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.

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>";
?>    


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";
...
?>

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.