Jump to content

Count suggestions


Schlo_50

Recommended Posts

Hello,

 

I am having some problems with the formatting of some data I am displaying on a page. I have a table in which the data is displayed within but I would ideally like to display 3 items per row of the table. At the moment my items are all in one row which looks untidy. Im not sure what php will make only 3 items display per row, or how to integrate it into my current code because of my foreach() loop. Could someone please help me?

 

print "<table width=\"100%\" align=\"center\" cellspacing=\"0\">";
print "<tr>";
  
$cid = $_GET['cid'];  
$linesb = file("admin/data/threads.DAT");
foreach ($linesb as $lineb) { 
$datab = explode("|", $lineb);
$imgdir = './admin/thumbs';
$imagename = trim($datab[1]);
$name = trim($datab[0]);	  

if(file_exists("$imgdir/$imagename.jpg")){
$img = "$imgdir/$imagename.jpg";
} else {
$img = "$noimgdir/comingsoon.jpg";
}

if ($cid == trim($datab[12])) {
print "<td><p align=\"center\"><a href=\"?id=view&item=$imagename\"><img src=\"$img\" border=\"0\"><br>$name</a><br>£$price<br>$add</p></td>\n";   
}
}
print "</tr>";
print "</table>";
print "<br><br>";

 

Thanks in advance!  ???

Link to comment
https://forums.phpfreaks.com/topic/107964-count-suggestions/
Share on other sites

try this

<?php
print "<table width=\"100%\" align=\"center\" cellspacing=\"0\">";
print '<tr>';
  
$cid = $_GET['cid'];  
$linesb = file("admin/data/threads.DAT");
//this is for count
$i = 0;
foreach ($linesb as $lineb) { 

$datab 		= explode("|", $lineb);
$imgdir 	= './admin/thumbs';
$imagename 	= trim($datab[1]);
$name	 	= trim($datab[0]);

if(file_exists("$imgdir/$imagename.jpg")){
	$img = "$imgdir/$imagename.jpg";
} else {
	$img = "$noimgdir/comingsoon.jpg";
}
    
if ($cid == trim($datab[12])) {
	if($i %3 == 0 && $i != 0){
		echo '< /tr> <tr>';
	}
	print "<td>
			<p align=\"center\">
				<a href=\"?id=view&item=$imagename\">
					<img src=\"$img\" border=\"0\">
					<br>$name
				</a>
				<br>
				£$price
				<br>
				$add
			</p>
		  </td>";
	$i++;
}

}
//this is for valid XHTML. since you may have 10/11 entry. so u must have to full fill the table
if(($i-1)%3 != 0) {
while (1) {
	if($i%3 == 0){
		echo '</tr>';
		break;
	} else {
		echo '<td> </td>';
	}

}
}

print "</table>";
print "<br><br>";
?>

Link to comment
https://forums.phpfreaks.com/topic/107964-count-suggestions/#findComment-553375
Share on other sites

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.