Table max 3 <td> loop in other tr - php

How to make it like only 3 offers in row NOW I have one row and all offer is in one line I just want to to show max 3 td in tr and loop.
if(count($offer_list['item']) > 0)
{
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item)
{
$main_content .= '<td class="shop">
<a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged)
{
$main_content .= '<p><b>[Login to buy]</b>';
}
else
{
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
$main_content .= '';
}
$main_content .= '</tr></table>';
}

$row_count = 1;
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item) {
// Check, if we are at position "1". If so, start new row
if ($row_count === 1) { $main_content .= '<tr>'; }
$main_content .= '<td class="shop"><a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged) {
$main_content .= '<p><b>[Login to buy]</b>';
}
else {
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
// Check, if we we are at position "3". If so, end row. (set position back to 1)
// Otherwise increase position with one level.
if ($row_count === 3) {
$row_count = 1;
$main_content .= '</tr>';
}
else {
$row_count++;
}
} // end foreach
// This is code for filling the "blank" table cells, if you don't have exactly some item count / 3 = 0
if ($row_count !== 3) {
for ($i=0; $i<=(3-$row_count); $i++) {
$main_content .= '<td> </td>';
}
$main_content .= '</tr>';
}
$main_content .= '</table>';
PS: <center> is deprecated or more to say not valid HTML anymore.

Related

Color table row by status

I wanna do if in by my status field.
if my status is "blocked" so the font background color will be in red and if the status is "authorized" so in green.
how should i do that?
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>
<td>'.$row->status.'</td>
</tr>
';
}
Try this
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>
#if($row->status == "blocked")
<td> <button type="button" class="btn btn-danger">blocked</button> </td>
#elseif($row->status == "authorized")
<td> <button type="button" class="btn btn-success">authorized</button> </td>
#endif
</tr>
OR
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}
You shouldn't really be dealing with view logic in your controller.
But to do what you want in the controller
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}
However what you should do is handle it in your blade file. Also you probably want to create styles in your style sheet and apply classes rather than inline the css.
this is the code that worked
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}

show 2 images in a row and the start a new row for next image in php

I am trying to show 2 images in a row .Curruntly when an image is displayed then the next image goes to a new row .what i want is that when 2 images are displayed in a row only then it should go to the next row .
for($i = 0; $i < $counter; $i++)
{
$path = "http://verfix.com/playground_app/assets/images/upload/".$data['inspection'][$i]->image;
$toolcopy .= '<tr style"height:350px;">
<td style="width:100px;">
P-'.$data['inspection'][$i]->id.'
</td>
<td style="width:420px;">
<img src="'.$path.'" width="420" height="220">
</td>
</tr>';
}
$toolcopy .= '</table>[![enter image description here][1]][1]
Thank You for any help .
Try with this code, it should do the trick.
$toolcopy = '<table>';
for($i = 0; $i < $counter; $i++)
{
$path = "http://verfix.com/playground_app/assets/images/upload/".$data['inspection'][$i]->image;
if($i === 0 || $i % 2 === 0) {
if($i > 0) $toolcopy .= '</tr>';
$toolcopy .= '<tr style"height:350px;">';
}
$toolcopy .= '
<td style="width:100px;">
P-'.$data['inspection'][$i]->id.'
</td>
<td style="width:420px;">
<img src="'.$path.'" width="420" height="220">
</td>';
}
$toolcopy .= '</tr>';
$toolcopy .= '</table>';[![enter image description here][1]][1]
It places two images in two separate TD elements in the same TR, the next two images on the next row and so on.

How to bind dynamic data in for loop

I have created the table in for loop to bind the images and after every 4 td i want to close the tr and its working fine. But im getting the last record only. please help me out.
foreach($show_banners as $keys=>$values)
{
$id=$values['id'];
$image_path=$values['image_path'];
$width=$values['width'];
$height=$values['height'];
$html_table = '<table id="mt" width="100%" style="margin-left:20px;"><tr>';
for($i=1;$i<=$tc;$i++)
{
$html_table .="<td ><img class='center-block' src='$site_url$image_path' height='$width' width='$height'></td>";
if ($i % 4 == 0)
$html_table .= "</tr><tr>"; // Close and reopen the <tr> tag
}
$html_table .='</tr></table>';
}
See this.. it will give the output you want
$html_table = '<table id="mt" width="100%" style="margin-left:20px;"><tr>';
foreach($show_banners as $keys=>$values)
{
$id=$values['id'];
$image_path=$values['image_path'];
$width=$values['width'];
$height=$values['height'];
for($i=1;$i<=$tc;$i++)
{
$html_table .="<td ><img class='center-block' src='$site_url$image_path' height='$width' width='$height'></td>";
if ($i % 4 == 0)
$html_table .= "</tr><tr>"; // Close and reopen the <tr> tag
}
$html_table .='</tr>';
}
$html_table.= "</table>";
echo $html_table;

Three shop offers in row

if(count($offer_list['item']) > 0)
{
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item)
{
$main_content .= '<td class="shop">
<a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged)
{
$main_content .= '<p><b>[Login to buy]</b>';
}
else
{
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
$main_content .= '';
}
$main_content .= '</tr></table>';
}
How to make it like only three offers in row? NOW I have one row and all offer is in one line; I just want to show max three td in tr and loop.
if you only want 3 tds in a row, build it into your loop:
//opener
<table>
//1st row
foreach($offer_list['item'] as $item) {
content.= <tr>;
content.= <td>$item[id]</td><td>$item[image]</td><td>$item[etc]</td>;
content.= <tr>;
//2nd row
content.= <tr>;
content.= <td>$item[description]</td><td>$item[etc]</td><td>$item[etc]</td>;
content.= <tr>;
}
content.=</table> //or div, etc
however it sounds like you want to position elements around like a product? Use inline divs for this. (no point in a example unless you elaborate what you want to do..)

Using jquery to hide and show php dynamicly created content "Search Results"

I have a table that displays my search results, and pending if a user has a function open I want to only display 5 results per row, and the same if they have it closed I want to show 7 results. This is working fine, but the issue I am having is when I toggle the function the div is hidden or shows but the PHP content that was dynamically created is still visible. I know that the div hides or shows pending the function because I wrote static text in the dynamically create divs and pending the function the text is shown or hidden.
Question: How to hide the php content as well?
PHP content =
/*BIG*/
//begin new row
if($result_incBig == $beginRowBig){
$b .= '<tr>';
//row color
$row_color = ($color_incBig % 2) ? 'tdAltRow_A' : 'tdAltRow_B';
if($i == ($num_qk-1)){
$secondRowClass = 'tdAltRow_noBorder';
}else{
$secondRowClass = 'tdAltRow';
}
//increment the color of the row
++$color_incBig;
}
$b .= '<td class="td_formTitle_noBorder" align="center" style="padding:0px; text-indent: 0;" width="165" height="115" valign="bottom">';
$b .= '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
$b .= '<tr>';
$b .= '<td align="center" style="height:80px; padding:4px; vertical-align:middle;">'.$appendLinkBegin.$companyPic.$appendLinkEnd.'</td>';
$b .= '</tr>';
$b .= '<tr>';
$b .= '<td align="center" style="height:35px; padding:2px; vertical-align:bottom;">'.$appendLinkBegin.'<b>'.$company_name.'</b>'.$addSpace.'<br />'.$num2.' '.$resultText.$appendLinkEnd.'</td>';
$b .= '</tr>';
$b .= '</table>';
$b .= '</td>';
//end row if out of results or reached max num for row
if($result_incBig == $endRowBig){
$b .= '</tr>';
$result_incBig = 0;
}else if(($i+1) == $num_qk){
if($result_incBig < $endRowBig){
for($e=0;$e<=($endRowBig-$result_incBig);++$e){
$b .= '<td class="td_formTitle_noBorder" align="center" style="padding:0px; text-indent: 0;" width="165" height="115" valign="bottom"><!--space--></td>';
}
$b .= '</tr>';
$result_incBig = 0;
}
}
//increment inc
++$result_incBig;
/*END BIG*/
/*SMALL*/
//begin new row
if($result_incSmall == $beginRowSmall){
$s .= '<tr>';
//row color
$row_color = ($color_incSmall % 2) ? 'tdAltRow_A' : 'tdAltRow_B';
if($i == ($num_qk-1)){
$secondRowClass = 'tdAltRow_noBorder';
}else{
$secondRowClass = 'tdAltRow';
}
//increment the color of the row
++$color_incSmall;
}
$s .= '<td class="td_formTitle_noBorder" align="center" style="padding:0px; text-indent: 0;" width="165" height="115" valign="bottom">';
$s .= '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
$s .= '<tr>';
$s .= '<td align="center" style="height:80px; padding:4px; vertical-align:middle;">'.$appendLinkBegin.$companyPic.$appendLinkEnd.'</td>';
$s .= '</tr>';
$s .= '<tr>';
$s .= '<td align="center" style="height:35px; padding:2px; vertical-align:bottom;">'.$appendLinkBegin.'<b>'.$company_name.'</b>'.$addSpace.'<br />'.$num2.' '.$resultText.$appendLinkEnd.'</td>';
$s .= '</tr>';
$s .= '</table>';
$s .= '</td>';
//end row if out of results or reached max num for row
if($result_incSmall == $endRowSmall){
$s .= '</tr>';
$result_incSmall = 0;
}else if(($i+1) == $num_qk){
if($result_incSmall < $endRowSmall){
for($e=0;$e<=($endRowSmall-$result_incSmall);++$e){
$s .= '<td class="td_formTitle_noBorder" align="center" style="padding:0px; text-indent: 0;" width="165" height="115" valign="bottom"><!--space--></td>';
}
$s .= '</tr>';
$result_incSmall = 0;
}
}
//increment inc
++$result_incSmall;
/*END SMALL*/
}
//display table
if($where == ''){
$b = '<input type="hidden" name="numberRes" id="numberRes" value="No Results" />';
$s = '<input type="hidden" name="numberRes" id="numberRes" value="No Results" />';
}
echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
//results
echo '<div class="rowFillBig">big7Results'.$b.'</div>';
echo '<div class="rowFillSmall" style="display:none;">small5Results'.$s.'</div>';
echo '</table>';
The Jquery function:
$(function () {
$('#tab_1').click(function(){
$('#tab_vid').toggle();
if ($("#mainContentRF").width() == 825){
$("#mainContentRF").width(1180);
$("audio").width(800);
//if viewing the full screen pause video
<?php if($viewingVideo > ''){ ?>
video = $('.videoplayer').get(0);
video.pause();
<?php } ?>
<!--hide small-->
$(".rowFillSmall").css("display", "none");
<!--show big-->
$(".rowFillBig").css("display", "inline");
}else{
$("#mainContentRF").width(825);
$("audio").width(500);
<!--show small-->
$(".rowFillSmall").css("display", "inline");
<!--hide big-->
$(".rowFillBig").css("display", "none");
}
<!--if tab was left open dont close it-->
<?php if($acc_openValue_1 == '99'){ ?>
})
<?php }else{ ?>
}).click();
<?php } ?>
});
If I can be more clear please let me know. Basically the div and any content inside should hide when asked to, and show when asked.
Place the div's on the outside of the table like this.
echo '<div class="rowFillBig">';
echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
//results
echo $b;
echo '</table>';
echo '</div>';
echo '<div class="rowFillSmall" style="display:none;">';
echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
//results
echo $s;
echo '</table>';
echo '</div>';

Categories