Table Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Table Problems

Post 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>";
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

I do believe that this has been asked quite a few times before.

Have a look at Useful Posts
Hemlata
Forum Commoner
Posts: 35
Joined: Mon Sep 10, 2007 5:40 am
Location: India
Contact:

Post 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]
Post Reply