Jump to content

[SOLVED] 2 Columns echoed from the MySQL Database


suttercain

Recommended Posts

Hi Guys,

 

I know this has been asked before but I am having a lot of trouble, even when looking at older posts, on this same request.

 

I currently have this code:

<div class="leftcontainer">RECENT COMICS:</div>
			<div class="curlycontainer1">
			<div class="innerdiv">
			<table width="468" border="0" cellspacing="0" cellpadding="2">
				<?php
				//COMIC Genrator
$sql1 = mysql_query ("SELECT title, 
							 comic_id, 
							 issue_number, 
							 cover_art, 
							 cover_artists, 
							 writers, 
							 pencillers, 
							 cover_date 
					  FROM comics 
					  WHERE type ='Comic Book' 
					  ORDER BY comic_id 
					  DESC LIMIT 0, 4");

while ($row1 = mysql_fetch_assoc($sql1)){
$cover_date = date('F, Y', strtotime($row1['cover_date']));
echo "<tr>";
echo "<td width='70'><a href='/comics/view_comics.php?id={$row1['comic_id']}'><img src='images/4ndvddb/" . $row1['cover_art'] . "' height='75px' width='50px'/></a><br></td>";
echo "<td><b><a href='/comics/view_comics.php?id={$row1['comic_id']}'>" . $row1['title'] . " #" . $row1['issue_number'] . "</a></b><br>Cover Date: " . $cover_date . "<br>Written By: " . 
				$row1['writers'] . "<br>Cover Artists: " . $row1['cover_artists'] . "<br>Artists: " . $row1['pencillers'] . "</td>";
echo "</tr>";
}
?>
</table>

 

It echos the information as such:

IMAGE1 text info

IMAGE2 text info

IMAGE3 text info

IMAGE4 text info

 

I would like to echo the information in two columns as such:

IMAGE 1              IMAGE 2

text info              text info

 

IMAGE 3              IMAGE 4

text info              text info

 

 

How would I achieve this? Does it involve the modules %? Thanks for the help in advance guys!

 

SC

yeah modulus will work.

<div class="leftcontainer">RECENT COMICS:</div>
			<div class="curlycontainer1">
			<div class="innerdiv">
			<table width="468" border="0" cellspacing="0" cellpadding="2">
				<?php
				//COMIC Genrator
$sql1 = mysql_query ("SELECT title, 
							 comic_id, 
							 issue_number, 
							 cover_art, 
							 cover_artists, 
							 writers, 
							 pencillers, 
							 cover_date 
					  FROM comics 
					  WHERE type ='Comic Book' 
					  ORDER BY comic_id 
					  DESC LIMIT 0, 4");
$i = 0;
        echo "<tr>\n";
while ($row1 = mysql_fetch_assoc($sql1)){
$cover_date = date('F, Y', strtotime($row1['cover_date']));
echo "<td width='70'><a href='/comics/view_comics.php?id={$row1['comic_id']}'><img src='images/4ndvddb/" . $row1['cover_art'] . "' height='75px' width='50px'/></a><br></td>";
echo "<td><b><a href='/comics/view_comics.php?id={$row1['comic_id']}'>" . $row1['title'] . " #" . $row1['issue_number'] . "</a></b><br>Cover Date: " . $cover_date . "<br>Written By: " . 
				$row1['writers'] . "<br>Cover Artists: " . $row1['cover_artists'] . "<br>Artists: " . $row1['pencillers'] . "</td>";
echo (($i % 2 == 0) ? ("</tr><tr>") : (""));
        $i++;
}
?>
        </tr>
</table>

 

i think that will work.

Hi guys, I tried both of those and here were the results:

 

Boo_Lolly's echoed the results like this:

IMAGE1 Text Description

IMAGE2 Text Description  IMAGE3 Text Description

IMAGE4 Text Description

 

And Marf's slightly altered line of code echoed the results like this:

IMAGE1 Text Description IMAGE2 Text Description  IMAGE3 Text Description

IMAGE4 Text Description

 

Any other suggestions? Thanks again for the time.

 

Alright I altered the code a little bit by takeing out a <td></td> tag and now have this:

 

<table width="468" border="0" cellspacing="0" cellpadding="2">
				<?php
				//COMIC Genrator
$sql1 = mysql_query ("SELECT title, 
							 comic_id, 
							 issue_number, 
							 cover_art, 
							 cover_artists, 
							 writers, 
							 pencillers, 
							 cover_date 
					  FROM comics 
					  WHERE type ='Comic Book' 
					  ORDER BY comic_id 
					  DESC LIMIT 0, 4");
$i = 0;
        echo "<tr>\n";
while ($row1 = mysql_fetch_assoc($sql1)){
$cover_date = date('F, Y', strtotime($row1['cover_date']));
echo "<td width='231'><a href='/comics/view_comics.php?id={$row1['comic_id']}'><img src='images/4ndvddb/" . $row1['cover_art'] . "' height='75px' width='50px'/></a><br>";
echo "<b><a href='/comics/view_comics.php?id={$row1['comic_id']}'>" . $row1['title'] . " #" . $row1['issue_number'] . "</a></b><br>Cover Date: " . $cover_date . "<br>Written By: " . 
				$row1['writers'] . "<br>Cover Artists: " . $row1['cover_artists'] . "<br>Artists: " . $row1['pencillers'] . "</td>";
echo ((($i % 2 == 0) && ($i > 0)) ? ("</tr><tr>") : (""));
        $i++;
}
?>
        </tr>
</table>

 

So now the result look like this,

 

IMAGE 1        IMAGE 2            IMAGE 3

Text Desc      Text Desc        Text Desc

 

IMAGE 4

Text Desc

 

I am almost there I just need to get IMAGE 3 and the Text description below IMAGE 1.

 

Any ideas?

 

<div class="leftcontainer">RECENT COMICS:</div>
			<div class="curlycontainer1">
			<div class="innerdiv">
			<table width="468" border="0" cellspacing="0" cellpadding="2">
				<?php
				//COMIC Genrator
$sql1 = mysql_query ("SELECT title, 
							 comic_id, 
							 issue_number, 
							 cover_art, 
							 cover_artists, 
							 writers, 
							 pencillers, 
							 cover_date 
					  FROM comics 
					  WHERE type ='Comic Book' 
					  ORDER BY comic_id 
					  DESC LIMIT 0, 4");
$i = 0;
        echo "<tr>\n";
while ($row1 = mysql_fetch_assoc($sql1)){
$i++;
$cover_date = date('F, Y', strtotime($row1['cover_date']));
echo "<td width='70'><a href='/comics/view_comics.php?id={$row1['comic_id']}'><img src='images/4ndvddb/" . $row1['cover_art'] . "' height='75px' width='50px'/></a><br></td>";
echo "<td><b><a href='/comics/view_comics.php?id={$row1['comic_id']}'>" . $row1['title'] . " #" . $row1['issue_number'] . "</a></b><br>Cover Date: " . $cover_date . "<br>Written By: " . 
				$row1['writers'] . "<br>Cover Artists: " . $row1['cover_artists'] . "<br>Artists: " . $row1['pencillers'] . "</td>";
echo (($i % 2 == 0) ? ("</tr><tr>") : (""));
}
?>
        </tr>
</table>

Does that work?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.