Page 1 of 1

Table Problems

Posted: Tue Sep 18, 2007 1:36 am
by kkonline
I am using the following code to display the images from the database.

Currently it just displays the image,title and date in one row and then the other images in next row

However i want to create two columns and display all the images in following fashion

r1c1 image1 then r1c2 image2 then r2c1 image3 then r2c2 image4 and so on...

what to do ?

Code: Select all

echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
while($row = mysql_fetch_array($sql))
{
$name= $row['name'];
$tcheck=$safeurl->make_safe_url($row['title']);

echo "<tr><td width='25%'>";
    echo ' <img src="/addons/class.upload/test/'.$name.'" />';
echo '<br />';
    echo '<a href="/'.$sid.'/'.$catid.'/'.$row['id'].'/0/'.$tcheck.'"><strong>' .$row['title'].'</strong></a>'; 
echo '<br />';
    echo " [ ";
    echo date("d/m/Y", $row['date'])."";
    echo " ] </td></tr>";
}
echo "</table>";

Posted: Tue Sep 18, 2007 3:08 am
by aceconcepts
I do believe that this has been asked quite a few times before.

Have a look at Useful Posts

Posted: Tue Sep 18, 2007 3:55 am
by Hemlata
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello [b]kkonline[/b], 

 Below is the solution for your issue of displaying the records in two columns. Hope this helps you.

Code: Select all

<table border="1" cellpadding="5" cellspacing="5" align="center" width="100%" valign="center">
<?php
// Intialize counter variable
$i = 0;

// fetch all the records
while($row = mysql_fetch_array($result))
{
	// Increment the counter and check for the even and odd number
	$i += 1;
	if ($i%2 == 0)
	{	
		echo "<td>" . $i . "Place Image 1 record</td>";
		echo "</tr>";
	}
	else	
	{			
		echo "<tr>";
		echo "<td>" . $i . "Place Image 2 record</td>";
	}
}
?>
</table>


Regards,


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]