Product Specification in table grid view in magento..! - php

I m inserting the data in description in magento...!!
but I'm getting a paragraph...!!
but inorder to get tabular format I had to write the HTML code manually.
So is there any solutions to get the tabular format autmatically.
For example follow below pic:

Create maximum attributes for specification add those.
like spec_1.spec_2,......
then display those attributes values in specification section in table format.
For example:
<table class="data-table" id="product-attribute-specs-table-4">
<col width="25%" />
<col />
<tbody>
<?php if (0 == strcmp($attributeSetName, 'Clothing')): ?>
<tr>
<th class="label">Clothing Shape</th>
<td class="data"><?php echo $_product->getClothing_shape() ?></td>
</tr>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Clothing Lining</th>
<td class="data"><?php echo $_product->getClothing_lining() ?></td>
</tr>
<?php elseif (0 == strcmp($attributeSetName, 'Sleeping Bags')): ?>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Inner Fabric</th>
<td class="data"><?php echo $_product->getInner_fabric() ?></td>
</tr>
<tr>
<th class="label">Filling</th>
<td class="data"><?php echo $_product->getFilling() ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table-4')</script>

Related

PHP Nesting do-while loop

Im trying to teach myself php.... I have created a database with 4 elements... region, details, store_name, web_address.
I have created ado-while loop that displays all the records in a 'region'... it displays 'store_name', then 'web_address', then 'details' sorted so all the records with the same 'details' are grouped together;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<tr>
<td width="14">
<td width="313"><?php echo $row_RegionList['details']; ?> </tr>
<?php } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
I now want to make it so every record with the same 'details' value get listed under a 'details' sub heading.
This is my attempt;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php $details = $row_RegionList['details'];
do { ?>
<tr>
<td width="313"> <h3><?php echo $row_RegionList['details']; ?> </h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<?php } while ($row_RegionList['details'] == $details);
$details = $row_RegionList['details'];
} while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
This makes a heading of 'region' with a sub heading of 'details' but then creates an eternal loop of the first record in the database. can someone show me what I have done wrong?

Table inside nested Table

I am having a nested table with a while loop, I want to add one more nested table in the same row:
Now I want to add one more nested table as each cd contains more than one data like below:
My code is as follows
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td><?php echo $rowcd['well_no'] ?></td>
<td><?php echo $rowcd['well_name'] ?></td>
<td>
<table border="1" width="100%">
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
/* I want to add one more nested table here*/
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
I tried some thing like this,after my second while loop
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
<td>
<table>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<tr>
<td><?php echo $rowl['logs'] ?></td>
</tr>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
but the result was messed up. I am confused, where I want to end my while loop, I think.
Finally i got as i wish, and i am sharing the code as below
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div class="container">
<table border="1" align="center" border-collapse="collapse">
<thead>
<tr >
<th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th width="100">CD No:</th>
<th width="150">Logs</th>
<th width="100">Bottom Depth</th>
<th width="100">Top Depth</th>
<th width="100">Date of Log</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td align="center"><?php echo $rowcd['well_no'] ?></td>
<td align="center"><?php echo $rowcd['well_name'] ?></td>
<td colspan="5">
<table rules="all">
<tr>
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<td width="100" align="center"><?php echo $rowcd['cd_no'] ?></td>
<td colspan="4">
<table rules="all">
<tr>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<td width="155"><?php echo $rowl['logs'] ?></td>
<td width="105" align="center"><?php echo $rowl['bottom'] ?></td>
<td width="100" align="center"><?php echo $rowl['top'] ?></td>
<td width="100" align="right"><?php echo $rowl['date'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
</td>
<?php
}
}
?>
</tr>
</table>
I hope this is what you meant as per your data table shown above
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<tr>
<td>id</td>
<td>well</td>
<td>name</td>
<td>
<table border="1" width="100%">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table border="1" width="100%">
<tr>
<td>Log1</td>
</tr>
<tr>
<td>Log2</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

How to do formatting using CSS to table

I am trying to design the table but it seems coming into proper way but for some cases. In this table, that $cal_amount and $cal_amount_key part shouldbe print whole for any numbers of cars.
Code:
PHP
<?php
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
?>
CSS
table,td,th,tr {
border:1px solid black;
border-collapse: collapse;
text-align:left;
}
HTML
<table>
<tr>
<th>S.No</th><th align="center">Variety of Goods</th><th style="width:70px">No.and Description of<br/>Packages</th><th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th><th style="width:70px">Total Quantity<br/>(Pcs)</th><th style="width:70px">Rate per pc.</th><th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++)
{?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<?php
}?>
<td colspan="1">Total Value</td><td style="width:100px;text-align:right;"> <?php echo $gro_tot;?></td>
<tr><td></td><td></td>
<td></td><td></td><td></td><td></td><td style="width:150px;">C.Ex.Duty 12.5%</td><td style="width:150px;text-align:right;"> <?php echo $Cex;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td></td><td style="width:150px;">SubTotal</td><td id="num" style="width:150px;text-align:right;"> <?php echo $S_Tot;?></td></tr>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td style="width:150px;">VAT/CST 2%</td><td style="width:150px;text-align:right;"> <?php echo $Vat;?></td></tr>
<tr><td style="border:none;" colspan="3"><b>qwert</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Freight</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td></tr>
<tr><td style="border:none;" colspan="3"><b>asdf</b></td><td style="border:none;"></td><td style="border:none;" colspan="2"><td><b>Grand Total</b></td><td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td></tr>
</tr>
</table>
Please suggest some changes to be done in code so that It will start from first row instead of third row. Thanks in advance.
Try this:
First make PHP array for total calculation and label.
$TotV=array("car","bus","jeep");
$Nopkg=array(759,159,459);
$Avg=array(20,50,15);
$Qty=array(15000,58000,58922);
$rate=array(31.73,17.15,17.25);
$gro_tot=789456;
$Cex=781254;
$S_Tot=159254;
$Vat=12500;
$frieght=0;
$G_Tot=985251;
$cal_amount_key = array('Total Value',
'C.Ex.Duty 12.5%',
'SubTotal',
'VAT/CST 2%',
'Freight',
'Grand Total');
$cal_amount = array($gro_tot,
$Cex,
$S_Tot,
$Vat,
$frieght,
$G_Tot);
Put the code inside loop:
<table>
<tr>
<th>S.No</th>
<th align="center">Variety of Goods</th>
<th style="width:70px">No.and Description of<br/>Packages</th>
<th style="width:70px">Avg. Contents per Package<br/>(Pcs)</th>
<th style="width:70px">Total Quantity<br/>(Pcs)</th>
<th style="width:70px">Rate per pc.</th>
<th colspan="2" style="text-align:center;">Amount<br/>(Rs.)</th>
</tr>
<?php
for($i=0;$i<count($TotV);$i++) {?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo strtoupper($TotV[$i]);?></td>
<td><?php echo $Nopkg[$i];?></td>
<td><?php echo $Avg[$i];?></td>
<td><?php echo $Qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
<td><?php echo $cal_amount_key[$i];?></td>
<td style="width:100px;text-align:right;"><?php echo $cal_amount[$i];?></td>
</tr>
<?php } ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td style="width:150px;">VAT/CST 2%</td>
<td style="width:150px;text-align:right;"> <?php echo $Vat;?></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>qwert</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Freight</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $frieght;?></STRONG></td>
</tr>
<tr>
<td style="border:none;" colspan="3"><b>asdf</b></td>
<td style="border:none;"></td>
<td style="border:none;" colspan="2">
<td><b>Grand Total</b></td>
<td style="width:150px;text-align:right;"> <STRONG><?php echo $G_Tot;?></STRONG></td>
</tr>
</table>

While loop to get PHP data into two different tables in HTML

Using a while loop to get my data out from PHP will only show all my data is vertical in a table form.
How can I show the data in horizontal form:
<?php
while ($display = mysqli_fetch_array($link)) {
if ($display['see_id'] % 2 == 0) {
?>
<table border='0' width='550px'>
<tr height='50px' style="text-align:center">
<td><?php echo $display['name']; ?></td>
</tr>
<tr>
<td><?php echo $display['video']; ?></td>
</tr>
<tr height='50px'>
<td><?php echo $display['description']; ?></td>
</tr>
<tr height='50px'>
<td></td>
</tr>
</table>
<?php }}
?>
You can put some style in your table: style="width:50%; float:left"
With while loop, of course.
<table border='0' style="width:50%; float:left">
<tr height='50px' style="text-align:center">
<td>Name</td>
</tr>
<tr>
<td>Video</td>
</tr>
<tr height='50px'>
<td>Description</td>
</tr>
<tr height='50px'>
<td></td>
</tr>
</table>
<table border='0' style="width:50%; float:left">
<tr height='50px' style="text-align:center">
<td>Name</td>
</tr>
<tr>
<td>Video</td>
</tr>
<tr height='50px'>
<td>Description</td>
</tr>
<tr height='50px'>
<td></td>
</tr>
</table>

Table rowspan issue

I have the following table. The header is at it looks and the content is generated within a PHP loop. It contains some taxes that a user has to pay and a tax can be paid in installments. For example, if the user has to pay a 100$ tax and he first pays 25$ and then 75$, there will be two rows in the table for that tax.
What I seem to fail to accomplish is to make a rowspan so the tax name will be displayed only once.
Any help is appreciated.
<table cellpadding="0" cellspacing="0" width="100%" class="sortable">
<thead>
<tr>
<th width="10%">Tax name</th>
<th width="10%">Value</th>
<th width="10%">Paid</th>
<th width="10%">Rest</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sign-up tax</td>
<td>100$</td>
<td>25$</td>
<td>75$</td>
</tr>
<tr>
<td>Sign-up tax</td>
<td>100$</td>
<td>75$</td>
<td>0$</td>
</tr>
</tbody>
</table>
The PHP code looks like this:
<?php for ($i = 0; $i < count($tax_details); $i++): ?>
<tr>
<td><?php echo $tax_details[$i]['name']; ?></td>
<td><?php echo $tax_details[$i]['value']; ?></td>
<td><?php echo $tax_details[$i]['paid']; ?></td>
<td><?php echo $tax_details[$i]['rest']; ?></td>
</tr>
<?php endfor; ?>
replace the html with this:
<tbody>
<tr>
<td rowspan="2">Sign-up tax</td> <---add rowspan here
<td>100$</td>
<td>25$</td>
<td>75$</td>
</tr>
<tr>
<td>100$</td> <---remove second sign-up tax from here
<td>75$</td>
<td>0$</td>
</tr>
</tbody>
Your code looks correct, I don't see the problem.
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="sortable">
<thead>
<tr>
<th width="10%">Tax name</th>
<th width="10%">Value</th>
<th width="10%">Paid</th>
<th width="10%">Rest</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($tax_details); $i++): ?>
<tr>
<td><?php echo $tax_details['name']; ?></td>
<td><?php echo $tax_details['value']; ?></td>
<td><?php echo $tax_details['paid']; ?></td>
<td><?php echo $tax_details['rest']; ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
I fail to understand what you are asking.

Categories