I have table data which is taking data from foreach and looping through a for loop.(looping 3 times with different values from foreach)
I want to know that how can I put a word in last <td> ?
my code;
<?php
foreach($halls_all_array AS $row){?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">
time1-<?php echo format_time($row[$start]['time'])?>
</td>
<?php } ?>
foreach($halls_all_array AS $row){
for($j=$start;$j<$limit;$j++){ ?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left"> time1-<?php echo format_time($row[$j]['time'])
if($j==($limit-1)){ echo "word";}
?>
</td>
<?php
}
}
?>
View
<?php foreach(... ) { ?>
<td>loop td</td>
<?php } ; ?>
Use :
if($j == ($limit - 1)) {
// last <td> here. You can add the text here.
}
EDIT
<?php
$count = count($halls_all_array);
$i = 0;
foreach($halls_all_array AS $row){
?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">time1-<?php echo format_time($row[$start]['time'])?>
<?php
if(++$i === $count){
//echo 'WORD TO PRINT';
}
?>
</td>
<?php
}
?>
Try the following
// first of all check $halls_all_array and $start are defined or not
<?php
$count=count($halls_all_array);
$i=1;
foreach($halls_all_array AS $row){
echo'<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">time1-'.format_time($row[$start]['time']);
if($i == $count){
//echo 'WORD TO PRINT';
}
echo'</td>';
$i++;
}
?>
Try this code
<?php
$length = count($halls_all_array); // TAKE THE LENGTH OF ARRAY
$i = 1;
foreach($halls_all_array as $row){ ?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">
<?php if($i < $length){ ?>
time1- <?php echo format_time($row[$start]['time']);?>
<?php }else{
echo "YOUR WORD..."; // Last Looping..
} ?>
</td>
<?php
$i++; // INCREMENT THE COUNTER
} ?>
first get the last key from array
end($halls_all_array); // move the internal pointer to the end of the array
$last_key = key($halls_all_array);// fetches the key of the element pointed to by the internal pointer
try this code:
<?php
/*get the last key*/
end($halls_all_array);
$last_key = key($halls_all_array);
foreach($halls_all_array as $key => $row){?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">
time1-<?php echo format_time($row[$start]['time'])?>
</td>
<?php if ($last_key == $key): ?>
<td><?php echo $row ?></td>
<?php endif ?>
<?php } ?>
Please write code like this:
<?php
$counter = 0; // start a counter
$total_count = count($halls_all_array); //total Counts
foreach($halls_all_array AS $row){?>
<td nowrap class="auto-style34" style="height: 30px; width: 20%" align="left">
time1-<?php echo format_time($row[$start]['time'])?>
<?php if($total_count==$counter) echo 'word'; ?> // you condition for last and word
</td>
<?php
$counter++;
}
?>
Related
I want red color as the background for the last second row of the table.
But it is not changing.
I tried:
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT * FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$allRows = $stmttr->rowCount(); // Count Total rows available in result
$tri = 0; // initiate variable to check <tr> status
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if(++$tri==$allRows) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
See the full code:
<?php
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT * FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$allRows = $stmttr->rowCount(); // Count Total rows available in result
$tri = 0; // initiate variable to check <tr> status
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if(++$tri==$allRows) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $i; ?>
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php
$itm = $IRN;
$stmti = $user_home->runQuery('SELECT * FROM item WHERE IRN = :iinv ');
$stmti->bindParam(':iinv',$itm);
$stmti->execute();
$rowci = $stmti->fetch(PDO::FETCH_ASSOC);
echo $rowci['Name'];
$srv = $SRN;
$stmts = $user_home->runQuery('SELECT * FROM service WHERE SRN = :sinv ');
$stmts->bindParam(':sinv',$srv);
$stmts->execute();
$rowcs = $stmts->fetch(PDO::FETCH_ASSOC);
?>
(<?php echo $rowcs['Name']; ?>)
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $Quantity; ?>
</td>
<td style="border-top:none !important; border-bottom:none !important;">
<?php echo $Amnt; ?>
</td>
</tr>
The error is at: $allRows = $stmttr->rowCount(); // Count Total rows available in result
It is not counting the rows available in MySQL
The updated code:
$i = 0;
$total = 0;
$stmttr = $user_home->runQuery("SELECT COUNT(*) As rows FROM invoice WHERE BRN = :inv"); // Your query
$stmttr->bindParam(':inv',$irn);
$stmttr->execute();
$cresult = $stmttr->fetch(PDO::FETCH_ASSOC);
$tf= ($cresult['rows']);
while($rowc)
{
extract($rowc);
$i++;
?>
<tr <?php if($i == $tf) { ?> style="background-color: red;"<?php } ?> >
<td style="border-top:none !important; border-bottom:none !important;">
Hope it helps you. Good Luck!!
Maybe you have a problem on your loop. What are on variable $rowc?
Maybe you should add <table> before the first <tr> and </table> after
the last </tr>?
And CSS should be in a css file, better practice!
I don't have your DB, but this code is working, if it's what you want.
<?php
$tri = 0;
$nbrows=10;
?>
<table>
<?php
while ($tri<$nbrows) { ?>
<tr <?php if(++$tri==$nbrows) { echo "style=\"background-color: red;\"";} ?> >
<td style="border-top:none !important; border-bottom:none !important;">Your content </td>
<td style="border-top:none !important; border-bottom:none !important;">Content 2 </td>
</tr>
<?php
}
?>
</table>
There are 5 types of prices that have been summed-up in each div using MySQL query and works perfectly.
Then, I wish to get the sum of those 5 total values by giving them each a $_SESSION variable before it sum them all up. It only gets the first price but still sums them up perfectly.
(e.g $extra_price is 25 then if i $extra_price+$extra_price the $total can get 50)
Lets say if (e.g $extra_price is 25 and $decoprice is 10 then i sum $extra_price+$decoprice the $total only show 25) the 10 has been ignore.
Any idea how to get the sum perfectly ?
Below is my code:
<?php
$extra_price = $_SESSION['extra_price'];
$decoprice = $_SESSION['decoprice'];
$foodprice = $_SESSION['foodprice'];
$drinksprice = $_SESSION['drinksprice'];
$venueprice = $_SESSION['venueprice'];
$total = $extra_price+$decoprice+$foodprice+$drinksprice+$venueprice;
?>
<center><b>Total <?php echo $total ?></b></center>
U shouldnt use this syntax
$_SESSION['decoprice'] = $show_pextra['SUM(decoprice)'];
Try to name you SUM(decoprice) and use it to register the session.
select SUM(decoprice) as sum_decoprice from selectdeco where title = '$title'
$_SESSION['decoprice'] = $show_pextra['sum_decoprice '];
You don't need all those extra variables, you can just write it like this:
$total = 0;
$keys = array('extra_price', 'decoprice', 'foodprice', 'drinksprice', 'venueprice');
foreach ($keys AS $key)
{
$total += $_SESSION[$key];
}
Obviously, this is irrelevant, just an issue of style. In any case the + operator will sum things perfectly for you. That's what it does. It sums things. Perfectly.
But the problem is, nobody knows what's in your $_SESSION. Do you? Why don't you try logging it somewhere or at least doing:
print_r($_SESSION);
Then you will see that your session probably doesn't contain what you think it does.
Hey first of all you don't need session here. Simple declare total variable at top of your code and replace each session with total variable with plus. and remove extra variables.
Replace
$_SESSION['extra_price'] = $show_pextra['SUM(price)'];
With
$total += $show_pextra['SUM(price)'];
Do with all session.
Here is your full code:
<?php $total = 0;?>
<tr><!--extra-->
<td style="width:120px;border:2px solid #000;"> Extra Item:</td>
<td style="border:2px solid #000;">
<?php
$read_allextra = mysql_query("select * from selectextra where title = '$title'");
while($show_allextra = mysql_fetch_array($read_allextra))
{
?>
<b>♦ <?php echo $show_allextra['extraitem'] ?></b></br>
<?php
}
?></td>
<td style="width:120px;border:2px solid #000;">
<?php
$read_pextra = mysql_query("select SUM(price) from selectextra where title = '$title'");
while($show_pextra = mysql_fetch_array($read_pextra))
{
?>
<center><b>RM <?php echo $show_pextra['SUM(price)'] ?></b></center>
<?php
$total += $show_pextra['SUM(price)'];
}
?>
</td>
</tr>
<tr><!--deco-->
<td style="width:120px;border:2px solid #000;"> Decoration :</td>
<td style="border:2px solid #000;">
<?php
$read_alldeco = mysql_query("select * from selectdeco where title = '$title'");
while($show_alldeco = mysql_fetch_array($read_alldeco))
{
?>
<b>♦ <?php echo $show_alldeco['decoitem'] ?></b></br>
<?php
}
?>
</td>
<td style="width:120px;border:2px solid #000;">
<?php
$read_pdeco = mysql_query("select SUM(decoprice) from selectdeco where title = '$title'");
while($show_pdeco = mysql_fetch_array($read_pdeco))
{
?>
<center><b>RM <?php echo $show_pdeco['SUM(decoprice)'] ?></b></center>
<?php
$total += $show_pextra['SUM(decoprice)'];
}
?>
</td>
</tr>
<tr><!--food-->
<td style="width:120px;border:2px solid #000;"> Foods :</td>
<td style="border:2px solid #000;">
<?php
$read_allfood = mysql_query("select * from selectfood where title = '$title'");
while($show_allfood = mysql_fetch_array($read_allfood))
{
?>
<b>♦ <?php echo $show_allfood['fooditem'] ?></b></br>
<?php
}
?>
</td>
<td style="width:120px;border:2px solid #000;">
<?php
$read_pfood = mysql_query("select SUM(foodprice) from selectfood where title = '$title'");
while($show_pfood = mysql_fetch_array($read_pfood))
{
?>
<center><b>RM <?php echo $show_pfood['SUM(foodprice)'] ?></b></center>
<?php
$total += $show_pextra['SUM(foodprice)'];
}
?>
</td>
</tr>
<tr><!--drinks-->
<td style="width:120px;border:2px solid #000;"> Drinks :</td>
<td style="border:2px solid #000;">
<?php
$read_alldrinks = mysql_query("select * from selectdrinks where title = '$title'");
while($show_alldrinks = mysql_fetch_array($read_alldrinks))
{
?>
<b>♦ <?php echo $show_alldrinks['drinksitem'] ?></b></br>
<?php
}
?>
</td>
<td style="width:120px;border:2px solid #000;">
<?php
$read_pdrinks = mysql_query("select SUM(drinksprice) from selectdrinks where title = '$title'");
while($show_pdrinks = mysql_fetch_array($read_pdrinks))
{
?>
<center><b>RM <?php echo $show_pdrinks['SUM(drinksprice)'] ?></b></center>
<?php
$total += $show_pextra['SUM(drinksprice)'];
}
?>
</td>
</tr>
<tr><!--venue-->
<td style="width:120px;border:2px solid #000;"> Venue :</td>
<td style="border:2px solid #000;">
<?php
$read_allvenue = mysql_query("select * from selectvenue where title = '$title'");
while($show_allvenue = mysql_fetch_array($read_allvenue))
{
?>
<b>♦ <?php echo $show_allvenue['venuename'] ?></b></br>
<?php
}
?>
</td>
<td style="width:120px;border:2px solid #000;">
<?php
$read_pvenue = mysql_query("select venueprice from selectvenue where title = '$title'");
while($show_pvenue = mysql_fetch_array($read_pvenue))
{
?>
<center><b>RM <?php echo $show_pvenue['venueprice'] ?></b></center>
<?php
$total += $show_pextra['SUM(venueprice)'];
}
?>
</td>
</tr>
<tr>
<td style="border:2px solid #000;" colspan="2">
<center><input type="submit" class="button" style="width:300px;" value="Pay Now" name="send_payment"/></center></td>
<td style="width:120px;border:2px solid #000;">
<center><b>Total <?php echo $total ?></b></center>
</td>
</tr>
I have products list,i have tried to align three products in a column and scroll towards right.how to shows only 9 ( 3 rows * 3 columns) products .this is my code.
<div style="border:solid 1px red;width:230px;overflow-x:scroll;">
<h4>Items/Products</h4>
<hr>
<table border="0">
<?php $count =0;
for($pr=0;$pr < count($items_list);$pr++){ ?>
<?php if($count % 3 == 0) { ?> <tr> <?php } ?>
<td style="border:solid 1px black;width:100px;height:40px;text-align:center">
<?php echo $items_list[$pr]->category;?>
</td>
<?php if($count % 3 == 0) { ?> </tr> <?php } ?>
<?php $count++;
} ?>
</table>
</div>
I have tried exactly look like this see here. How to change my code?
You need to use Ajax Pagination or Jquery Scolling to become (http://postimg.org/image/eifr7azob/)
Try this,
<div style="border:solid 1px red;width:430px;overflow-x:scroll;">
<h4>Items/Products</h4>
<hr>
<table border="0">
<tr>
<?php $count =1; //$countItems = count($items_list);
$countItems =11;
for($pr=0;$pr < $countItems;$pr++){ ?>
<td style="border:solid 1px black;width:100px;height:40px;text-align:center"> <?php echo $pr;?>
<?php //echo $items_list[$pr]->category;?>
</td>
<?php if($count % 3 == 0) { ?> </tr><tr><?php } ?>
<?php $count++; } ?>
</table>
</div>
3 Rows x N columns
<div style="border:solid 1px red;width:430px;overflow-x:scroll;">
<h4>Items/Products</h4>
<hr>
<table border="0">
<tr>
<?php $count =1;
//$items_list_count = count($items_list);
$items_list_count = 25;
$Rows = 3;
$coulmns =#ceil($items_list_count/$Rows);
for($pr=0;$pr < $items_list_count;$pr++){ ?>
<td style="border:solid 1px black;width:100px;height:40px;text-align:center">
<?php //echo $items_list[$pr]->category;?> <?php echo $pr;?>
</td>
<?php if($count % $coulmns == 0) { ?> </tr><tr><?php } ?>
<?php $count++; } ?>
</table>
</div>
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while ($pF = mysql_fetch_array($stringVisits)) {
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if (checkStatus($BuID) == 1) {
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if (!empty($getByProfile["photo_thumb"])) {
echo $getByProfile["photo_thumb"];
} else {
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php } ?>
</tr>
</table>
This is what i have right now it displays the visiter´s profileimage. Now i would like to have their name under the image too.. but then i need to create another <tr> after this one, and add their name in each <td>. But how can i do that, if i have this while? Should i run another while, to get the names or can i do something smart with this?
Why not just stick the name in the same cell as the image? After you close the image tag, just echo $getByProfile["username"], or whatever?
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while($pF = mysql_fetch_array($stringVisits)){
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'><br/>";
?>
</a>
<br/><?php echo $getByProfile['username']; ?>
</td>
<?php } ?>
</tr>
</table>
Here's a way to do it with minimal changes to your existing code:
<?php
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
$names = array(); // ADDITION #1
while($pF = mysql_fetch_array($stringVisits)){
$names[] = // ADDITION #2 - ADD NEW USER NAME HERE;
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php }
// ADDITION #3:
echo "</tr>
<tr>";
foreach ($names as $username)
echo "<td class=\"username\"><p>$username</p></td>";
?>
</tr>
</table>
Also note that the way you had your code, the </tr> was inside the while loop.
this might not look nice but it should work why do you want 2 loops?
<?php
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >";
while($pF = mysql_fetch_array($stringVisits)){
echo "
<tr>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<a href='profil.php?id=".$BuID."'> <img /> </a>
</td>
</tr>
<tr><td> " . $getByProfile['username'] . " </td></tr>";
}
echo "</table>";
?>
I am populating the images from my database in a table, how to restrict the images to three per row?
<table border="0" align="center" height="25%" width="25%" >
<tr><td align="center" width="50px" bgcolor="#4b2d0e"><strong><font color="#FFFFFF">Friend List</font></strong></td></tr>
<? foreach($Selected as $row)
{
$value = $row['dPath'];
$imgp = base_url()."images"."/".$value;
?>
<tr><td bgcolor="#999999">
<strong ><?=$row['dFrindName'].'</br>';?></strong>
<? if($value!="") { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="<?=$imgp ?>" name="b1" width="90" height="80" border="0"/></a><br>
<? } else { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="../images/us.png" width="90px" height="80px"></a>
<? }?>
</td></tr>
<? }}?>
</table>
This is my table
<?php
$x=0;
foreach($Selected as $row){
if($x%3 == 0)
echo '<tr>';
$value = $row['dPath'];
$imgp = base_url()."images"."/".$value;
?>
<td style="background-color:#999999;">
<strong ><?=$row['dFrindName'].'</br>';?></strong>
<?php if($value!="") {?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="<?=$imgp ?>" name="b1" width="90" height="80" border="0"/></a><br>
<?php } else { ?>
<a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="../images/us.png" width="90px" height="80px"></a>
<?php }?>
</td>
<?php
if($x%3 == 0)
echo '</tr>';
x++;
}
if(($x-1)%3 != 0)
echo '</tr>'; //Prints out the last '<tr>' if one isn't printed.
?>
You need to use an if with a modulus operator.
Here, I cleaned up your invalid HTML, used CSS, and used a more recommended PHP coding style.
Please note: you need to be aware that if $Selected contains user-inputted (or otherwise non-HTML-safe) data, you need to wrap your output in htmlspecialchars or be open to XSS vulnerabilities.
It was a little unclear what you meant by wanting to "restrict the images to three per row" considering that it was only showing 1 per row currently. If I am to assume that you want to show 3 per row rather than 1, than you need to use the modulus operator and only open a new <tr> after every third element, and then close it at the right time. Like this:
<style type="text/css">
a img { border: none; }
.friend-list { border: none; width: 25%; height: 25%; margin: 0 auto; }
.friend-list th { text-align: center; background-color: #4b2d0e; color: #fff; font-weight: bold; }
.friend-list td { background-color: #999999; }
</style>
<?php
$numCols = 3;
$colCount = -1;
?>
<table class="friend-list">
<tr>
<th colspan="<?php echo $numCols; ?>">Friend List</th>
</tr>
<?php
foreach($Selected as $row) {
$value = $row['dPath'];
$imgp = ($value) ? base_url().'images/'.$value : '../images/us.png';
if(++$colCount % $numCols == 0) {
echo '<tr>';
}
?>
<td>
<strong><?php echo $row['dFriendName']; ?></strong><br />
<a class="Tab_Link" href="<?php echo site_url(); ?>/friends/View_FProfile/<?php echo $row['dMember_Id']; ?>">
<img src="<?php echo $imgp; ?>" width="90" height="80" />
</a>
</td>
<?php
if(($colCount + 1) % $numCols == 0) {
echo '</tr>';
} elseif (($colCount + 1) == count($Selected)) {
// if 16 elements are to fit in 3 columns, print 2 empty <td>s before closing <tr>
$extraTDs = $numCols - (($colCount + 1) % $numCols);
for ($i = 0; $i < $extraTDs; $i++) {
echo '<td> </td>';
}
echo '</tr>';
}
}
?>
</table>
Tables should be reserved for situations where columns and rows have meaning... A better solution is to use floated block elements instead of table cells. When you float a bunch of similar blocks, they wrap automatically, so the key is making their parent container just wide enough to hold 3 of them.
You don't need to do anything special with php to create new rows, so i'll just display the html and css, letting you write the php to make it happen.
html:
<div id="replacesTable">
<div class="replacesTableCell">
<div class="name">Name</div>
<img src="http://stackoverflow.com/favicon.ico" />
</div>
<div class="replacesTableCell">
<div class="name">Name</div>
<img src="http://stackoverflow.com/favicon.ico" />
</div>
<div class="replacesTableCell">
<div class="name">Name</div>
<img src="http://stackoverflow.com/favicon.ico" />
</div>
<div class="replacesTableCell">
<div class="name">Name</div>
<img src="http://stackoverflow.com/favicon.ico" />
</div>
<div class="clear"> </div>
</div>
css:
#replacesTable{
width: 300px;
}
div.replacesTableCell{
float:left;
width: 100px;
/* styles below are just to make it easier to see what's happening */
text-align:center;
font-size: 10px;
margin: 20px 0;
}
/* this just stretches the parent container #replacesTable around the entries*/
.clear{
clear:both;
height:1px;
overflow:hidden;
}
You can use CSS as an alernative if the images are of a fixed width and you can do without the tables - create a wrapper div with a fixed width around your entire image list, and simply float each image left.
Here is a simplified example without the extraneous styling information to show the principal. Every 3rd image we want to write the opening and closing tags (though not at the same time).
So we loop through the list of images and use the moduulus operator to know when we should print the <tr> tags.
<?php
$column_count = 3;
$image_list = get_images();
?>
<table>
<?php
for($i=0; $i < sizeof($image_list); i++) {
$cur_img = $image_list[$i];
$img_url = $cur_img['url'];
// open a we row every 3rd column
if($i % $column_count == 0) {
print '<tr>';
}
// for every image we want a table cell, and an image tag
print "<td> <img src='$img_url'> </td>";
// close the row every 3rd column, but offset by 3 from the opening tag
if($i % $column_count == $column_count - 1) {
print '<tr>';
}
}
// what if the number of images are not div by 3? Then there will be less
// than 3 items in the last row, and no closing tag. So we look for that and
// print a closing tag here if needed
if(sizeof($image_list) % $column_count != 0) {
print '</tr>';
}
?>
</table>
You can try using http://www.php.net/manual/en/function.array-chunk.php
Hey, would you try this.
Notice that I replaced the if...else with a ternary operator. I prefer it compact.
Hope it helps you and anyone else interested.:)
<table border="0" align="center" height="25%" width="25%" >
<tr>
<td colspan="3" align="center" width="50px" bgcolor="#4b2d0e">
<strong><font color="#FFFFFF">Friend List</font></strong>
</td>
</tr>
<?
$imgs=0;
foreach($Selected as $row){
$value = $row['dPath'];
$imgp = base_url()."images"."/".$value;
if($imgs%3 == 0){
echo '<tr>';
}
?>
<td bgcolor="#999999">
<strong ><?=$row['dFrindName'].'</br>';?></strong><a class="Tab_Link" href="<? echo site_url();?>/friends/View_FProfile/<?=$row['dMember_Id']?>"><img src="<?=$value!=""? $imgp: '../images/us.png' ?>" name="b1" width="90" height="80" border="0"/></a>
</td>
<?
$imgs++;
if($imgs%3 == 0){
echo "</tr>\n";
}
}//end loop
echo '</tr>';//end last row
?>
</table>