Three shop offers in row - php

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..)

Related

How to change the cell color of HTML table according to a threshold

I have a mysql query as below in my php page,
$query = "
select table_date as Date,vals as Value from usertable.table1 group by table_date;";
I am fetching data to columns from below method.
$result=mysqli_query($conn,$query);
while ($row = $result -> fetch_assoc())
{
$q2Date .= '<td style="text-align:center"><b>'.$row['Date'].'</td>';
$q2Value .= '<td style="text-align:center">'.$row['Value'].'</td>';
$row['Date']++;
}
Then I am using $body variable as below to show them in a html table.
$body.= '
<table style="top: 15px; left:10px; " border=1>
<tbody>
<caption style="color: rgb(241, 239, 243);background: rgb(1, 32, 65); ">Total Value</caption>
<tr>
<td style="text-align:center"><b>Date</td>'.$q2Date .'
</tr>
<tr>
<td style="text-align:center"><b>Value</td>'.$q2Value .'
</tr>
</tbody>
</table>
';
From above method I could get the output as below,
Now I need to check each cell and change its color if it differs more than 25% from average value(lets say 250). Then the output should show as follows,
What changes to be done in my original code? Do I need to change my query as well? or HTML or both?
check if value is greater than 250 then set background color style:
<?php
$result=mysqli_query($conn,$query);
while ($row = $result -> fetch_assoc())
{
$q2Date .= '<td style="text-align:center"><b>'.$row['Date'].'</td>';
if($row['Value'] >= 250)
$q2Value .= '<td style="text-align:center;background-color:red;">'.$row['Value'].'</td>';
else
$q2Value .= '<td style="text-align:center;">'.$row['Value'].'</td>';
$row['Date']++;
}
its so simple to create a class in CSS let's say lessCell
.lessCell{
background:red;
}
then check the value if it is true add the class to if it's not do nothing
$cls="";
$result=mysqli_query($conn,$query);
while ($row = $result -> fetch_assoc())
{
if(your_condition==true){
$cls='class="lessCell"';
}else{
$cls=""
}
$q2Date .= '<td '.$cls.' style="text-align:center"><b>'.$row['Date'].'</td>';
$q2Value .= '<td style="text-align:center">'.$row['Value'].'</td>';
$row['Date']++;
}

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;

Table max 3 <td> loop in other tr

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.

Mysql fetch array, table results 2

I've recently posted a similar question but that was to create one row of cells across and after it reaches 3 columns, it creates a new row, so I can have 3 columns of infinite rows. That was solved.
Now what I need is this (GIVEN A and B should be records from the database using $row = mysql_fetch_array($results) so basically it would be something like $row['username']; for A and B ).
<tr>
<td><img src="images/ava/A.png" /></td>
<td>A</td>
<td width="2px" rowspan="3"></td>
<td><img src="images/ava/B.png" /></td>
<td>B</td>
</tr>
<tr>
<td><div class="gauge"><div class="innergauge"></div>A</div></td>
<td><div class="gauge"><div class="innergauge"></div>B</div></td>
</tr>
<tr>
<td>A</td>
<td>B</td>
</tr>
As what you can see, the record I got from my database has to fill in to this format, where A is one record and B is another, then if there is record C, this whole thing should repeat again to form a second row.
Build each section as you go, combine them at the end. Here's how you do sections 1 and 3, the middle section is left as an exercise:
$section1 = '<tr>';
$section2 = // start $section2
$section3 = '<tr>';
$i = 0;
while($row = mysql_fetch_array(...)){
if($i > 0){
// won't happen the first time through the loop
$section1.= '<td width="2px" rowspan="3"></td>';
}
$section1 .= '<td><img src="images/ava/'.$row['username'].'"/></td>';
$section1 .= '<td>'.$row['username'].'</td>';
// now do $section2
$section3 .= '<td>'.$row['username'].'</td>';
$i++;
}
$section1 .= '</tr>';
// finish $section 2
$section3 .= '</tr>';
// now output
echo $section1 . $section2 . $section3;

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