Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using below coding to get an array result in a table,
$presents = #json_decode(fBGetDataStore('presents'), true);
foreach ($presents as $key=>$value){
$icon = $_SESSION['data']->table('units')->byCode($value['itemCode'])->data();
$i = 1;
echo '<table border=1 class="sortable" align="center">
<tr>
<td class="sortable" align="center">#</td>
<td class="sortable" align="center">Sender IMG</td>
<td class="sortable" align="center">Sender ID</td>
<td class="sortable" align="center">Item Code</td>
<td class="sortable" align="center">IMG</td>
</tr>';
echo '<tr><td align="center">'.$i++.'</td>';
echo '<td> <img src="http://graph.facebook.com/'. $value['sender'] .'/picture" width="70" height="50" </td>';
echo '<td align="center">'. $value['sender'] . '</td>';
echo '<td align="center">'. $value['itemCode'] . '</td>';
echo '<td><img src="http://static-0.farmville.zgncdn.com/assets/hashed/' . fBImageGetHash($icon['iconname']). '" width=45px height=45px ></td>' ;
echo '</tr>';
}
and also I'm getting a table but I want to count # of results in a sequence because right now my results are showing in many more than one tables which contain only one row.
I'm getting as a result :
echo '<table border=1 class="sortable" align="center">
<tr>
<td class="sortable" align="center">#</td>
<td class="sortable" align="center">Sender IMG</td>
<td class="sortable" align="center">Sender ID</td>
<td class="sortable" align="center">Item Code</td>
<td class="sortable" align="center">IMG</td>
</tr>';
$presents = #json_decode(fBGetDataStore('presents'), true);
foreach ($presents as $key=>$value){
$icon = $_SESSION['data']->table('units')->byCode($value['itemCode'])->data();
$i = 1;
echo '<tr><td align="center">'.$i++.'</td>';
echo '<td> <img src="http://graph.facebook.com/'. $value['sender'] .'/picture" width="70" height="50" </td>';
echo '<td align="center">'. $value['sender'] . '</td>';
echo '<td align="center">'. $value['itemCode'] . '</td>';
echo '<td><img src="http://static-0.farmville.zgncdn.com/assets/hashed/' . fBImageGetHash($icon['iconname']). '" width=45px height=45px ></td>' ;
echo '</tr>';
}
you need to print the table outside of loop, so only the relevent row will repeat itself.
just tested the 1st and 2nd answer (by both of them you will get 1 means same figure as # column so my opinion is you should use to count rows :
$presents = #json_decode(fBGetDataStore('presents'), true);
$i = 1;
// Table starting
echo '<table border=1 class="sortable" align="center">
<tr>
<td class="sortable" align="center">#</td>
<td class="sortable" align="center">Sender IMG</td>
<td class="sortable" align="center">Sender ID</td>
<td class="sortable" align="center">Item Code</td>
<td class="sortable" align="center">IMG</td>
</tr>';
foreach ($presents as $key=>$value){
$icon = $_SESSION['data']->table('units')->byCode($value['itemCode'])->data();
echo '<tr><td align="center">'.$i++.'</td>';
echo '<td> <img src="http://graph.facebook.com/'. $value['sender'] .'/picture" width="70" height="50" </td>';
echo '<td align="center">'. $value['sender'] . '</td>';
echo '<td align="center">'. $value['itemCode'] . '</td>';
echo '<td><img src="http://static-0.farmville.zgncdn.com/assets/hashed/' . fBImageGetHash($icon['iconname']). '" width=45px height=45px ></td>' ;
echo '</tr>';
}
echo '</table>'; //Table end
i hope you will get it as your need.
Related
I am trying to parse an HTML string which is a table. I managed to remove the first row of the table. How can I then remove the second column in the table?
I remove the first row like this:
$preparsed = "<div style='border:1px #CCCCCC dotted; padding:5px'><div style=''>
<div id='divPrint'>
<table cellpadding='5' cellspacing='0' width='886'>
<tr bgcolor='#666666' class='normal' style='color:#FFFFFF; font-weight:bold;'>
<td width='100px' style='font-size:11px;'><b>Type</b></td>
<td width='110px' style='font-size:12px;'><b>Date</b></td>
<td width='100px' style='font-size:12px;'><b>Details</b></td>
<td width='140px' style='font-size:12px;'><b>Instructor</b></td>
<td width='140px' style='font-size:12px;'><b>Student / Client</b></td>
<td style='font-size:12px;'><b>Comment</b></td>
</tr>
<tr class='normal' style='font-size:11px' bgcolor='#EEEEEE'>
<td style='font-size:12px;'>Training</td>
<td style='font-size:12px;'>2016-10-05 <br /><i class='small'>(16:00:00-18:00:00)</i></td>
<td style='font-size:12px;'>Zara</td>
<td style='font-size:12px;'>Gary</td>
<td style='font-size:12px;'>Alfred</td>
<td style='font-size:12px;'></td>
</tr><tr class='normal' style='font-size:11px' bgcolor='#FFFFFF'>
<td style='font-size:12px;'>Training</td>
<td style='font-size:12px;'>2016-10-05 <br /><i class='small'>(12:00:00-15:00:00)</i></td>
<td style='font-size:12px;'>Zara</td>
<td style='font-size:12px;'>Gary</td>
<td style='font-size:12px;'>shawn</td>
<td style='font-size:12px;'></td>
</tr>
</table>
</div>
</div></div>";
$html = new simple_html_dom();
$html->load($preparsed);
$rows = array_slice($html->find('tr'), 1);
foreach ( $rows as $element ) {
echo '<h3>'. $element->plaintext . '</h3>';
This removes the first row. How can I either a)First remove every second column in each row (the date), or b) remove the first row first and then remove all the second columns in each row?
Like this:
$html = new simple_html_dom();
$html->load($preparsed);
$rows = array_slice($html->find('tr'), 1);
foreach ( $rows as $element ) {
echo '<h3>'. $element->plaintext . '</h3>';
$cols = array_slice($element->find('td'), 2);
foreach ( $cols as $col ) {
echo '<h4>The second col os the row values '. $col->plaintext . '</h4>';
}
}
I'm trying to display data horizontally in a table by using PHP & MySQL. The code that I'm currently using is (Obviously all values will be called from MySQL but currently I have put static values):-
$query = "select * from bonusdetails where BonusType='Free Money' order by Validity ASC limit 0,3;";
$result = mysql_query($query);
echo '<table width="150" border="0" cellspacing="0" cellpadding="0" bgcolor="#941010" style="font-family:Arial, Helvetica, sans-serif; float:left; color:#ffffff;">';
while ($row = mysql_fetch_array($result))
{
echo '<tr>';
echo '<td align="center" style="padding:2px 0 0 0;"><img src="abc.jpg" width="124" height="64"/></td>';
echo '</tr>';
echo '<tr>';
echo '<td align="center" style="font-size:15px; padding:8px 0 0 0;">No Deposit Bonus</td>';
echo '</tr>';
echo '<tr>';
echo '<td style="font-size:17px; padding:5px 0 0 0;" align="center" >CODE: STAR75</td>';
echo '</tr>';
echo '<tr>';
echo ' <td align="center" style="padding:8px 0 5px 0;"><a href="#"><input name="more-details" type="button" style="background:url(images/more-details.png) no-repeat; width:102px;
height:27px; text-decoration:none; border:none; cursor:pointer;" /></a></td>';
echo '</tr>';
}
echo '</table>';
I'm getting output in this format: http://www.casinobonustips.com/submitbonus/bonus.php. is there a way to display the same data horizontally?
I will highly appreciate your assistance on this.
Thanks and Regards,
Devjeet
What you have:
<table>
<tr>
<td>A1</td>
</tr>
<tr>
<td>B1</td>
</tr>
<tr>
<td>C1</td>
</tr>
<tr>
<td>A2</td>
</tr>
<tr>
<td>B2</td>
</tr>
<tr>
<td>C2</td>
</tr>
<tr>
<td>A3</td>
</tr>
<tr>
<td>B3</td>
</tr>
<tr>
<td>C3</td>
</tr>
</table>
What you should have:
<table>
<tr>
<td>
<div>A1</div>
<div>B1</div>
<div>C1</div>
</td>
<td>
<div>A2</div>
<div>B2</div>
<div>C2</div>
</td>
<td>
<div>A3</div>
<div>B3</div>
<div>C3</div>
</td>
</tr>
</table>
Example: http://jsfiddle.net/ePMmx/1/
Do your styling to suit your needs.
You need to group <td></td> in one <tr></tr> to display them "horizontally", on the other hand, you are mixing "view" stuff with processing and retrieving the data, you maybe have to read about MVC pattern for better programming
I have the following generated column for "Detail"
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';
which gives me overall following table of results, where the particular column data overlaps when it is too long. What should I do? I have tried adding a '<br/>' in between, but it never worked.
Unfortunately this table had no external CSS file but the following is the full table
<table cellspacing="1" width="900" cellpadding="3" bgcolor="#CCCCCC" style="line-height:0px;margin-left: auto;margin-right: auto">
<col width="64" span="10" />
<tr height="46">
<td height="46" width="600" colspan="10" bgcolor="#FFFFFF"><h1>Blah Blah</h1></td>
</tr>
<?php
include './DatabaseConnection.php';
$db = new DatabaseConnection();
$db->createDatabaseConnection();
$cusid = $_GET['cusid'];
$startDate=$_GET['startDate'];
$endDate=$_GET['endDate'];
$query2 = mysql_query("select cusname from customers where cusid='$cusid'");
while ($row5 = mysql_fetch_array($query2)) {
echo '<tr height="20" width="1000">
<td height="10" colspan="10" bgcolor="#F3F3F3"><h2>Payment History of ' . $row5['cusname'] . ' (Credit)</h2></td>
</tr><tr height="20">
<td width="120" height="20" bgcolor="#FFFFFF"><h3>Date Added</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Number</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Amount</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Payed Amount</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Detail</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Balance</h3></td>
</tr>';
}
//$query = mysql_query("SELECT * from payments where cusid ='$cusid' and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());
$query = mysql_query("SELECT * from payments where cusid ='$cusid' and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());
$lastinvoicenumber = null;
while ($row1 = mysql_fetch_array($query)) {
$invoiceAmount = $row1['subtotal'];
$payedAmount = $row1['payment'];
$invoicenumber = $row1['invoiceGRN_id'];
$invoicetotal = 0;
//$balanceAmount = $invoiceAmount - $payedAmount;
$balanceAmount = $invoiceAmount;
//diluk
$queryinv = mysql_query("SELECT invoice_subtotal from invoice where invoice_number ='$invoicenumber' limit 1") or die(mysql_error());
//diluk
while ($rowinv = mysql_fetch_array($queryinv)) {
$invoicetotal = $rowinv['invoice_subtotal'];
}
echo '<tr height="20">
<td width="100" align="left" bgcolor="#FFFFFF">' . $row1['date_added'] . '</td>';
if($lastinvoicenumber!=$invoicenumber){
echo '<td width="100" height="20" bgcolor="#FFFFFF">' . $row1['invoiceGRN_id'] . '</td>';
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $invoicetotal . '</td>';
}else{
echo '<td width="100" height="20" bgcolor="#FFFFFF"></td>';
echo '<td width="100" align="right" bgcolor="#FFFFFF"></td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $row1['payment'] . '</td>';
$invId = $row1['invoiceGRN_id'];
if ($row1['paymentType'] == "Cheque") {
$query3 = mysql_query("select * from cheque where invoiceno='$invId'");
if ($row4 = mysql_fetch_array($query3)) {
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';
}else{
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque -' . $row1['date_added'] .'</td>';
}
} else {
echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $row1['paymentType'] . '</td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $balanceAmount . '</td>
</tr>';
$lastinvoicenumber = $invoicenumber;
}
echo '<tr height="20" width="1000">
<td height="10" colspan="10" bgcolor="#F3F3F3"><h2></h2></td></tr>';
$queryx = mysql_query("SELECT * from invoice where customer_id ='$cusid' and payment_type !='Credit' group by invoice_number order by invoice_date") or die(mysql_error());
while ($rowx = mysql_fetch_array($queryx)) {
echo '<tr height="20">
<td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['invoice_date'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_number'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>';
$invId1 = $rowx['invoice_number'];
if ($rowx['payment_type'] == "Cheque") {
$queryx1 = mysql_query("select * from cheque where invoiceno='$invId1'");
if ($rowx2 = mysql_fetch_array($queryx1)) {
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $rowx2['number'] . ')</td>';
}
} else {
echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['payment_type'] . '</td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">0</td>
</tr>';
}
?>
</table>
There are 2 things you have to consider:
1. table-layout: fixed; this for table, and
2. word-wrap: break-word; to td itself.
For detailed see this question: How to force table cell <td> content to wrap?
I have also faced the same problem, just add \n to the end of every <tr> tag like this
echo "<tr><td></td><td></td></tr> \n"
you can check
echo '<td width="100" align="left" bgcolor="#FFFFFF"><div style="width:200px; word-wrap: break-word;overflow: auto;">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</div></td>';
I solved the isue by making the table's "line-height" attribute to 20px like below,
<table cellspacing="1" width="900" cellpadding="3" bgcolor="#CCCCCC" style="line-height:20px;margin-left: auto;margin-right: auto">
in this code
"<td align="left">' .$row['o_id'] .'</td>"
i generate multiple o_id so when i click on other particular o_id this o_id post by other page and on that behalf i can access this o_id in multiple pages but i m trying to use hidden type but it not working so any other process to post this value other page....
it is possible to send this so please help me....
and one more thing i using hidden type but is not working also how it's work for post the value from one page to other page using html in php tag....
$sql1 = " select count(status) as count from bill_generation_request where hotel_id = '$hid' and status ='yes'";
$result = mysql_query($sql1);
while ($row = mysql_fetch_array($result))
{
$count = $row['count'];
}
echo '<table align="center" cellspacing="0" cellpadding="5" width="0%" border="1"> <tr>
<td align="left"><b>Bill Request Count</b></td>';
echo '<td align="left">' .$count . '</td> ';
echo '</tr>';
echo '</table>';
echo '<table align="center" cellspacing="0" cellpadding="5" width="75%" border="1">
<tr>
<td align="left"><b>Order Number</b></td>
<td align="left"><b>Table Number</b></td>
<td align="left"><b>Item Count</b></td>
<td align="left"><b>Order Time</b></td>
<td align="left"><b>Total Amount</b></td>
<td align="left"><b>Order Note</b></td>
<td align="left"><b>Note</b></td>
</tr> ';
$i=0;
while ($row = mysql_fetch_array($res))
{
$oid = $row['o_id'];
echo '<tr bgcolor="' . $bg . '">
<td align="left">' .$row['o_id'] .'</td>
<td align="left">' . $row['tableid'] . '</td>
<td align="left">' . $row['total_count'] . '</td>
<td align="left">' .$row['time'] . '</td>
<td align="left">' .$row['amount'] . '</td>
<td align="left">' .$row['onote'] . '</td>
<td align="left">' .$row['note'] . '</td>
</tr>';
$i++;
}
echo '</table>';
mysql_close($con);
Try like
$id = $row['o_id'];
<td align="left">' .$row['o_id'] .'</td>
and Use $_GET['id'] to get that id
Try this
$id = $row['o_id'];
<td align="left">' .$row['o_id'] .'</td>
I'm trying to echo data from an SQLdatabase into a table that is somewhat decent-looking. I can already echo the data properly into 5 separate basic tables, but when I can't figure out how to style it without it completely messing up. Here is the code I already have:
// OUTPUTS RESULTS //
$resultfirst = mysql_query("SELECT * FROM Students WHERE FirstPeriod='$_POST[firstperiod]'");
$resultsecond = mysql_query("SELECT * FROM Students WHERE SecondPeriod='$_POST[secondperiod]'");
$resultthird = mysql_query("SELECT * FROM Students WHERE ThirdPeriod='$_POST[thirdperiod]'");
$resultfourth = mysql_query("SELECT * FROM Students WHERE FourthPeriod='$_POST[fourthperiod]'");
$resultfifth = mysql_query("SELECT * FROM Students WHERE FifthPeriod='$_POST[fifthperiod]'");
// 1st PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>First Period</th>
</tr>";
while($row = mysql_fetch_array($resultfirst))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 2nd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Second Period</th>
</tr>";
while($row = mysql_fetch_array($resultsecond))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 3rd PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Third Period</th>
</tr>";
while($row = mysql_fetch_array($resultthird))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 4th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fourth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfourth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 5th PERIOD
echo "<table border='1' bgcolor='#3b5998' style='float:left; margin:20'>
<tr>
<th>Fifth Period</th>
</tr>";
while($row = mysql_fetch_array($resultfifth))
{
echo "<tr>";
echo "<td>" . $row['StudentName'] . "</td>";
echo "</tr>";
}
echo "</table>";
If the code above is unclear- my goal is to compare the first period teachers in which are stored in the database, and output the students names that share the same period/teacher.
This code works fine. But the tables look very bland. I would like to echo the data into a table such as this.
<table width="368" border="0" cellspacing="0" cellpadding="2" align="center" height="100">
<tr valign="middle">
<td bgcolor="#000066" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Services</font></b></font> </div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#990000" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Products</font></b></font></div>
</td>
<td width="4" height="20"></td>
<td bgcolor="#C89800" width="120" height="20">
<div align="center"><font color="#FFFFFF"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Web
Resources</font></b></font> </div>
</td>
</tr>
<tr valign="top">
<td bgcolor="#000066" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Professional
and cost effective web design, development and promotion services
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#990000" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Interactive
Web Products - Flash Survey, poll, Guest book, Instant Quote
</font></p>
</td>
</tr>
</table>
</td>
<td width="4"></td>
<td bgcolor="#C89800" width="120">
<table width="100%" border="0" cellspacing="0" cellpadding="3" height="80">
<tr bgcolor="#FFFFFF" valign="top">
<td>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Free
web resources - articles, tutorials, tips and tricks.
</font></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
If anyone can offer any suggestions of any sort- I would greatly appreciate it.
I see a few areas that can be improved:
As others have said, don't use tables to manage layout. However, tables are perfectly acceptable for displaying tabular data
You really want to use CSS to style your page, it's a lot easier to control your style and makes the markup easier to read. See this w3schools' artcile on CSS Tables
You can combine your multiple queries into one for better performance (though, that seems to be outside the scope of your question)
Here is an example markup and CSS for your table: http://jsfiddle.net/vxzJV/