I'm trying to show booking using tables, which have dynamic rows and also rowspan.
Here is my code:
<table border="1" style='width: 100%' >
<tr>
<th style='background-color:green;width: 80px' ><font color="white">Time</font></th>
<?php
$i=1;
while($i<=$no_court)
{
echo "<th style='background-color:green;width: 80px'> <font color='white'>Court".$i."</font></th>";
$i+=1;
}
?>
</tr>
<tr>
<td>8:00 AM</td>
<?php
$i=1;
while($i<=$no_court)
{
$flag=0;
$j=0;
while(sizeof($start) > $j )
{
$start_time=$start[$j];
$finish_time=$finish[$j];
$court=$court1[$j];
$sst = strtotime($start_time);
$eet= strtotime($finish_time);
$diff= $eet-$sst;
$timeElapsed= gmdate("h:i",$diff);
$timeElapsed+=1;
if ($start_time=='08:00:00' && $court==$i)
{
$fio_time=$finish[$j];
if($fio_time=='13:00:00')
{
$f_time='1:00:00';
}
$f=$facility_id[$j];
$sql15 = $dbConnection->prepare('SELECT * FROM tbl_facility WHERE facility_id=?');
$sql15->execute(array($f));
$row15 = $sql15->fetch();
$facility_name=$row15['facility_name'];
if($block_by[$j]=="1")
{
echo "<td style='background-color:blue;' rowspan='$timeElapsed'>
<font size='2' color='white'><b><center>$league[$j]</b></br>
Reserved </br>
$facility_name</br>
$start_time-$f_time</br>
<a href='' onClick='javascript: openPopup($id[$j])' style='color:white;'>Edit</a>
<a href='delete.php?id=$id[$j]' style='color:white;' onclick='return confirmdelete()' >Delete</a>
</center></font></td>";
break;
}
elseif($block_by[$j]=="2")
{
$p=$player_id[$j];
$sql17 = $dbConnection->prepare('SELECT * FROM tbl_player_registration WHERE player_id=?');
$sql17->execute(array($p));
$row17 = $sql17->fetch();
$first_name=$row17['first_name'];
echo "<td style='background-color:gray;' rowspan='$timeElapsed'>
<font size='2' color='white'><b><center>Reserved By</b></br>
$first_name </br>
</center></font></td>";
break;
}
}
elseif($start_time <='08:00:00' && $finish_time >='08:00:00' && $court==$i )
{
break;
}
elseif($court==$i )
{
$l=0;
while(sizeof($court) > $l)
{
$ta=$start[$l];
$fa=$finish[$l];
$ca=$court1[$l];
if($ta >='08:00:00' && $fa <='08:00:00' && $ca==$i )
{
$flag=1;$court=$ca;
}
$l+=1;
}
}
$j+=1;
}
if($flag==1 )
{
echo "<td></td>";
}
if($flag==0 )
{
}
if($court != $i)
{
echo "<td></td>";
}
$i+=1;
}
?>
</tr>
</table>
Its showing output as this image:
Its showing data properly but adding an extra column, which make the table look disturbing.
I want to show the result as this image:
I'm little confused where I'm messing the code. Kindly help to sort this issue.
Related
I am creating a component for teachers where in teacher can generate pdf for all the students who have completed the course.
Checking all the students and pdfs should be generated and saved on disk. After which a download link is provided to download the zip of all the pdfs generated. This is what i want to achieve. I am using fpdf for generating pdf.
Any suggestions ?
Below is the form that is posted and students id-
<form
action="<?php echo JRoute::_('index.php?option=com_mentor&view=download_certificate&cid=' . $cid . '&Itemid=529') ?>"
name="download_certificate" method="post" id="download_certificate">
<table class="adminlist" border="1" cellpadding="0" cellspacing="0"
style="table-layout: fixed" id="content">
<thead>
<tr>
<th class="nowrap" style="width: 35px">
<input type="checkbox" name="selectall" id="selectall">
</th>
<th class="nowrap" align="center">
<?php echo JText::_('COM_MENTOR_USER_NAME'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_COURSE_STATUS'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ENROLLMENT_DATE'); ?>
</th>
<th class="nowrap" style="width: 140px">
<?php echo JText::_('COM_MENTOR_ACTIVITY'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_SCORE'); ?>
</th>
<th class="nowrap" style="width: 50px">
<?php echo JText::_('COM_MENTOR_RESULT'); ?>
</th>
</tr>
</thead>
<tbody>
<?php
//echo '<pre>';print_r($this->mentor_details); die;
foreach ($this->mentor_details as $students) {
$cid = $this->mentor_details['cid'];
$i = 1;
foreach ($students['students'] as $student) {
$userid = $student['id'];
// echo '<pre>';
// print_r($student);
// die;
?>
<tr class="status" id="<?php echo $userid ?>">
<td align="center">
<input type="checkbox" id="<?php echo $userid ?>" name="check[]" class="checkbox1"
value="<?php echo $userid ?>">
</td>
<td>
<a href="<?php echo JRoute::_('index.php?option=com_mentor&view=grader&cid=' . $cid . '&uid='
. $userid . $itemid) ?>">
<?php echo $student['username']; ?>
</a>
</td>
<!-- <td>
<?php// echo $student['email']; ?>
</td> -->
<td align="center">
<?php
$incomplete = $completed = $not_started = 0;
for ($k = 0; $k < count($student['elements']); $k++) {
foreach ($student['elements'] as $elements) {
if ($elements['userid'] == $userid) {
// echo '<pre>';print_r($elements); die;
if ($elements['element']['cmi.core.lesson_status'] == 'incomplete') {
$incomplete++;
} else {
$completed++;
}
}
}
}
if ($incomplete == 0 && $completed == 0) {
echo 'Not yet started';
} else {
if ($completed == count($student['elements'])) {
echo 'Completed';
} else {
echo 'Incomplete';
}
}
?>
</td>
<td align="center">
<?php
if (!empty($student['timestart'])) {
$date = date('d-m-Y H:i', $student['timestart']);
echo $date;
} else {
echo "Not yet started";
} ?>
</td>
<td align="center">
<?php
if (!empty($student['activity']['lasttime']) && (!empty($student['activity']['starttime']))) {
$start_date = date('d-m-Y H:i', $student['activity']['starttime']);
$last_date = date('d-m-Y H:i', $student['activity']['lasttime']);
echo $start_date . '<br/>' . $last_date;
} else {
echo "-";
} ?>
</td>
<td align="center">
<?php
$grades = $student['grades'];
$total_grade = array();
$j = 0;
//for ($j = 0; $j < count($grades); $j++) {
// $total_grade[$j] = $grades[$j]['finalgrade'];
//}
//print_r($total_grade);die;
if (!empty($grades)) {
//echo number_format(array_sum($total_grade), 2);
$total_grade[$j] = $grades[$j]['finalgrade'];
echo number_format($total_grade[$j], 2);
} else {
echo '-';
}
//echo '<pre>';
//print_r($student['grades']);
//die;
?>
</td>
<td align="center">
<?php
//echo '<pre>';print_r($student);die;
if (!empty($student['scores'])) {
if (isset($grades[$j]['feedbacktext'])) {
echo $grades[$j]['feedbacktext'];
} else {
echo '-';
}
} else {
echo '-';
}
?>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</form>
<script>
function checked_value() {
var checkedValue = [];
var $len = $(".checkbox1:checked").length;
if ($len == 0) {
alert('Please select user');
}
// else if ($len > 1) {
// alert('Please select a single user only.');
// }
else {
$(".checkbox1").each(function () {
var $this = $(this);
if ($this.is(":checked")) {
checkedValue.push($this.attr("id"));
}
});
$("#download_certificate").submit();
</script>
On Clicking image tag, form is submitted with the students id and I am getting students data, his name, grades, course,
<img src="/components/com_mentor/images/certificate_blue.png" class="certificate-ico right"
title="Download Certificate" onclick="checked_value();"/>
After this processing, page is redirected to pdf.php page
require_once('/wamp/opt/bitnami/apache2/htdocs/lms/lib/fpdf/fpdf.php');
$pdf = new FPDF(); $pdf->SetFont('times', '', 12);
$pdf->SetTextColor(50, 60, 100); $pdf->AddPage('L');
$pdf->SetDisplayMode(real, 'default'); $pdf->SetXY(10, 60);
$pdf->SetFontSize(12);
$pdf->Write(5, 'Dear Ms.XYX');
$filename = "test.pdf";
$dir = "/assets/";
$pdf->Output($dir . $filename, 'F');
Thanks guys for your help.. Solved my question.
Looped through the pdf function for n no. of users.
we have an assignment for today in which we have to echo some data of the database. The data is month, case, vehicle_id. In a month there can be many cases and in a case there can be many vehicle_ids. What i have achieve to do is to show it in the following way
month st_case veh_id
1 10001 1000011
1 10002 1000021
1 10002 1000022
2 10058 1000581
using this code:
<table border="1">
<tr>
<th>month</th>
<th>st_case</th>
<th>veh_id</th>
</tr>
<?php
// Loop on rows in the result set.
for($ri = 0; $ri < $numrows; $ri++) {
echo "<tr>\n";
$row = pg_fetch_array($result, $ri);
echo " <td>", $row["month"], "</td>
<td>", $row["st_case"], "</td>
<td>", $row["veh_id"], "</td>
</tr>
";
}
pg_close($link);
?>
</table>
The problem is that what i really want to do is to make it show for each month the cases and for each case the vehicles.
1
10001
1000011
10002
1000021
1000022
2
10058
1000581
I tried to do something like this but it doesn't show correctly. If someone could help me with this i would be really thankfull.
<table border="1">
<tr>
<th>month</th>
<th>st_case</th>
<th>veh_id</th>
</tr>
<?php
// Loop on rows in the result set.
$currentmonth = 0;
for($ri = 0; $ri < $numrows; $ri++)
{
$row = pg_fetch_array($result, $ri);
if ($currentmonth != $row["month"])
{
echo "<tr>";
echo "<td>";
echo "<strong>".$row["month"]."</strong>";
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td>".$row["st_case"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$row["veh_id"]."</td>";
echo "</tr>";
$currentmonth = $row["month"];
}
pg_close($link);
?>
</table>
picture: http://i61.tinypic.com/2nb8vgl.png
$ret = pg_fetch_all($result);
$group = array();
foreach($ret as $v){
$group[$v['month']][$v['st_case']][] = $v['veh_id'];
}
foreach($group as $month=>$value){
echo $month."<br/>";
foreach($value as $st_case=>$v){
echo $st_case."<br/>";
foreach($v as $veh_id){
echo $veh_id."<br/>";
}
}
}
PS.then add some css to style your table
If you do not intend to display items in a table, do not use table
What you want is something like this:
<div class="result">
<div class="month_group">
<span class="month bold">1</span>
<div class="case_group">
<span class="case">10001</span>
<div class="veh_group">
<span class="veh_id">1000011</span>
</div>
<span class="case">10002</span>
<div class="veh_group">
<span class="veh_id">1000021</span>
<span class="veh_id">1000022</span>
</div>
</div>
</div>
<div class="month_group">
<span class="month">2</span>
<div class="case_group">
<span class="case">10058</span>
<div class="veh_group">
<span class="veh_id">1000081</span>
</div>
</div>
</div>
</div>
Then all that's left to do is applying simple css to give the classes some padding/margin.
HTML is a markup language. You structure the web page using the HTML tags. However, how it would look like depends more on css (which is why it's called Cascading Style Sheets).
Here's the rendering code. I have not tested it yet, and I have not touched PHP for sometime, but it should give you some general ideas:
echo "<div class=\"result\">";
for($ri = 0; $ri < $numrows; $ri++) {
$row = pg_fetch_array($result, $ri);
$month = $row["month"];
echo "<div class=\"month_group\">\n";
echo "<span class=\"month\">".$month."</span>\n";
echo "<div class=\"case_group\">\n";
for ($ci = $ri; $ci < $numrow; $ci++) {
if ($ci == $ri) {
$c_row = $row;
} else {
$c_row = pg_fetch_array($result, $ci);
}
if ($c_row["month"] != $month) {
// We have moved to another month
break;
}
$case = $c_row["st_case"];
echo "<span class=\"case\">".$case."</span>\n";
echo "<div class=\"veh_group\">\n";
for ($vi = $ci; $vi < $numrow; $vi++) {
if ($vi == $ci) {
$v_row = $c_row;
} else {
$v_row = pg_fetch_array($result, $vi);
}
if ($v_row["st_case"] != $case) {
// We have moved to another case
break;
}
$veh = $v_row["veh_id"];
echo "<span class=\"veh_id\">".$veh."</span>\n";
// we have already processed rows whose indexes are less or equal $vi
$ri = $vi;
}
echo "</div>";
}
echo "</div></div>";
}
Try this updated code
<table border="1">
<tr>
<th>month</th>
<th>st_case</th>
<th>veh_id</th>
</tr>
<?php
// Loop on rows in the result set.
$currentmonth = 0;
for($ri = 0; $ri < $numrows; $ri++)
{
$row = pg_fetch_array($result, $ri);
// Open the row
echo "<tr>";
echo "<td><strong>" . $row["month"] . "</strong></td>"; //open and close each column
echo "<td>".$row["st_case"]."</td>";
echo "<td>".$row["veh_id"]."</td>";
echo "</tr>"; //close the row
$currentmonth = $row["month"];
}
pg_close($link);
?>
</table>
You will also need to call the ORDER BY keyword in your MySQL statement to order by month.
Here is a simple tutorial on how to do this.
Here is a Demo of how it might look in your application.
Let me know if this helps and if i can be of any other help.
I am not very familiar with PHP or MySQL, but after researching here I have been able to learn and get very close to what I need and build my first sum query. I am trying to read the database and sum values based on several variables.
I need the reservation_pax from the reservations table where reservation_time is 8:00 where reservation_hidden = 0 and reservation_date is something. I can manually enter the date and it works. I am now trying to use a session code already in the script or find a way to to dynamically add based on selected date.
Here is the code I have working without the dynamic aspect or session.
$result = mysql_query("SELECT SUM(reservation_pax)
FROM reservations
WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'") ;
if ($result === false) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result)) {
echo $row['SUM(reservation_pax)'];
}
Here is the full code of the page where I entered the above addition. Can anyone help me figure out how to call the selected date rather than having to manually enter.
<!-- Begin reservation table data -->
<br/>
<table class="global resv-table-small" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<?php
echo "<td class='noprint'> </td>";
echo "<td>Time</td>";
echo "<td>Guests/Type</td>";
echo "<td>Name</td>";
echo "<td>Special Instructions/Notes</td>";
echo "<td class='noprint'>Table</td>";
echo "<td class='noprint'>Status</td>";
echo "<td class='noprint'>Created</td>";
echo "<td class='noprint'>Details/Delete</td>";
echo "</tr>";
// Clear reservation variable
$reservations ='';
if ($_SESSION['page'] == 1) {
$reservations = querySQL('all_reservations');
}else{
$reservations = querySQL('reservations');
}
// reset total counters
$tablesum = 0;
$guestsum = 0;
if ($reservations) {
//start printing out reservation grid
foreach($reservations as $row) {
// reservation ID
$id = $row->reservation_id;
$_SESSION['reservation_guest_name'] = $row->reservation_guest_name;
// check if reservation is tautologous
$tautologous = querySQL('tautologous');
echo "<tr id='res-".$id."'>";
echo "<td";
// daylight coloring
if ($row->reservation_time > $daylight_evening){
echo " class='evening noprint'";
}else if ($row->reservation_time > $daylight_noon){
echo " class='afternoon noprint'";
}else if ($row->reservation_time < $daylight_noon){
echo " class='morning noprint'";
}
echo " style='width:10px !important; padding:0px;'> </td>";
echo "<td id='tb_time'";
// reservation after maitre message
if ($row->reservation_timestamp > $maitre['maitre_timestamp'] && $maitre['maitre_comment_day']!='') {
echo " class='tautologous' title='"._sentence_13."' ";
}
echo ">";
echo "<strong>".formatTime($row->reservation_time,$general['timeformat'])."</strong></td>";
echo "<td id='tb_pax'><strong class='big'>".$row->reservation_pax."</strong> <span class='noprint'>";
printType($row->reservation_hotelguest_yn);
//echo "<img src='images/icons/user-silhouette.png' class='middle'/>";
echo "</span></td><td style='width:10%' id='tb_name'><span class='noprint'>".printTitle($row->reservation_title)."</span><strong> <a id='detlbuttontrigger' href='ajax/guest_detail.php?id=".$id."'";
// color guest name if tautologous
if($tautologous>1){echo" class='tautologous tipsy' title='"._tautologous_booking."'";}
echo ">".$row->reservation_guest_name."</a></strong>";
// old reservations symbol
if( (strtotime($row->reservation_timestamp) + $general['old_days']*86400) <= time() ){
echo "<img src='images/icons/clock-bolt.png' class='help tipsyold middle smicon' title='"._sentence_11."' />";
}
// recurring symbol
if ($row->repeat_id !=0) {
echo " <img src='images/icons/loop-alt.png' alt='"._recurring.
"' title='"._recurring."' class='tipsy' border='0' >";
}
echo"</td><td style='width:10%' id='tb_note'>";
if ($_SESSION['page'] == 1) {
echo $row->outlet_name;
}else{
echo $row->reservation_notes;
}
echo "</td>";
if($_SESSION['wait'] == 0){
echo "<td class='big tb_nr' style='width:85px;' id='tb_table'><img src='images/icons/table_II.png' class='tipsy leftside noprint' title='"._table."' /><div id='reservation_table-".$id."' class='inlineedit'>".$row->reservation_table."</div></td>";
}
echo "<td class='noprint'><div>";
getStatusList($id, $row->reservation_status);
echo "</div></td>";
echo "<td class='noprint'>";
echo "<small>".$row->reservation_booker_name." | ".humanize($row->reservation_timestamp)."</small>";
echo "</td>";
echo "<td class='noprint'>";
// MOVE BUTTON
// echo "<a href=''><img src='images/icons/arrow.png' alt='move' class='help' title='"._move_reservation_to."'/></a>";
// WAITLIST ALLOW BUTTON
if($_SESSION['wait'] == 1){
$leftspace = leftSpace(substr($row->reservation_time,0,5), $availability);
if($leftspace >= $row->reservation_pax && $_SESSION['outlet_max_tables']-$tbl_availability[substr($row->reservation_time,0,5)] >= 1){
echo" <a href='#' name='".$id."' class='alwbtn'><img src='images/icons/check-alt.png' name='".$id."' alt='"._allow."' class='help' title='"._allow."'/></a> ";
}
}
// EDIT/DETAIL BUTTON
echo "<a href='?p=102&resID=".$id."'><img src='images/icons/pen-fill.png' alt='"._detail."' class='help' title='"._detail."'/></a> ";
// DELETE BUTTON
if ( current_user_can( 'Reservation-Delete' ) && $q!=3 ){
echo"<a href='#modalsecurity' name='".$row->repeat_id."' id='".$id."' class='delbtn'>
<img src='images/icons/delete.png' alt='"._cancelled."' class='help' title='"._delete."'/></a>";
}
echo"</td></tr>";
$tablesum ++;
$guestsum += $row->reservation_pax;
}
}
?>
</tbody>
<tfoot>
<tr style="border:1px #000;">
<td class=" noprint"></td><td></td>
<td colspan="2" class="bold"><?php echo $guestsum;?> <?php echo _guest_summary;?></td>
<td></td>
<td colspan="2" class="bold"><?php echo $tablesum;?> <?php echo _tables_summary;?></td>
<td colspan="2" class="bold"><?php
$result = mysql_query("SELECT SUM(`reservation_pax`) FROM `reservations` WHERE `reservation_time` = '8:00:00' AND `reservation_date` = '{$_SESSION['selectedDate']}' AND `reservation_hidden` ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>
<?php echo '/ 40 ', _guest_summary, ' -8:00 AM';?></td>
<td></td>
<?php
if($_SESSION['wait'] == 0){
//echo "<td></td>";
}
?>
</tr>
</tfoot>
</table>
<!-- End reservation table data -->
you can use alias field, as:
$result = mysql_query("SELECT SUM(reservation_pax) AS reserve_sum
FROM reservations WHERE reservation_time = '8:00:00'
AND reservation_date = '2014-10-27'
AND reservation_hidden ='0'"
) ;
....
and get access it as:
while($row = mysql_fetch_array($result))
{
echo $row['reserve_sum'];
}
$result = mysql_query("SELECT SUM(reservation_pax) FROM reservations WHERE reservation_time = '8:00:00' AND reservation_date = '{$_SESSION['selectedDate']}' AND reservation_hidden ='0'") ;
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($result))
{
echo $row['SUM(reservation_pax)'];
}
?>
I know this has been asked before and I have got it working using the following code:
<?php
$maxcols = 8; $i = 0;
echo "<table id='table1'><tr>";
foreach ($id as $k => $v) {
echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++;
if ($i == $maxcols) { $i = 0; echo "</tr><tr>"; }
} $i++;
while ($i <= $maxcols) {
$i++; echo "<td></td>";
}
echo "</tr></table>";
?>
This results in a table that looks like this :
I'd like to add headers to this so the end result looks like this:
I'd like to do it dynamically so if I create a table that is only 5 columns wide I'd get on the first header row ID01 - ID05 and on the second header row ID06 - ID10
I want to limit the header ID values to be no more than $maxid any extra header fields should be blank, like this : If $maxid = 12; then :
I need the header rows are made as follows and not using <TH>
<td class="mark">
I'm using some javascript to allow the movement of cell data.
The class is used to set the formatting on the header and stop items from being dragged into the fields.
Can anyone point me in the right direction on how to do this.
This should help you.
$maxcols = 8;
$maxid = 12;
$startid = 1;
echo "<table id='table1'>\n";
for ($i = 1;$i<=ceil($maxid/$maxcols);$i++) {
echo "<tr>\n";
for ($j=1;$j<=$maxcols;$j++)
if ($startid <= $maxid)
echo " <td class='mark'>ID".$startid++."</td>\n";
else
echo " <td> </td>\n";
echo "</tr>\n<tr>\n";
for ($j=1;$j<=$maxcols;$j++)
echo "<td>Content</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
Generates
<table id='table1'>
<tr>
<td class='mark'>ID1</td>
<td class='mark'>ID2</td>
<td class='mark'>ID3</td>
<td class='mark'>ID4</td>
<td class='mark'>ID5</td>
<td class='mark'>ID6</td>
<td class='mark'>ID7</td>
<td class='mark'>ID8</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td class='mark'>ID9</td>
<td class='mark'>ID10</td>
<td class='mark'>ID11</td>
<td class='mark'>ID12</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</table>
try this. It will work in the same way as you desired
<?php
$id= array("1","2","3","4","5","6","7","8","9","10","11","12");
$maxcols = 8; $i = 0;$j=0;$t=0;$s=0;
$maxid = count($id);
echo "<table id='table1'><tr>";
foreach ($id as $k => $v)
{
if($t == 0)
{
while ($t <= $maxcols-1) {
if($s < $maxid)
{
$s++;$t++; echo "<td class='mark'>id$s</td>";
}
else
{
echo "<td class='mark'></td>";$t++;$s++;
}
}
echo "</tr><tr>";
}
else
{
}
echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++;
if ($i == $maxcols)
{
echo "</tr><tr>";
if($j == 0)
{
while ($j <= $maxcols-1) {
if($s < $maxid)
{
$s++;$j++; echo "<td class='mark'>id$s</td>";
}
else
{
echo "<td class='mark'></td>";$j++;$s++;
}
}
echo "</tr><tr>";
}
$i=0;
}
}
echo "</tr></table>";
?>
Output
Hi You can Use My Library:
class generate{
private $row = "<tr>{columns}</tr>";
private $td = "<td {attr}>{data}</td>";
private $attributeTR="";
private $attributeTD="";
private $tdBuilder="";
public function addCol($ColumValsArr=array("class='motota'"=>"Example")){
foreach($ColumValsArr as $key=>$val){
$newCol = str_replace("{data}",$val,$this->td);
$newCol = str_replace("{attr}",$key,$newCol);
$this->tdBuilder .= str_replace("{data}",$key,$newCol);
}
}
public function getRow(){
return str_replace("{columns}",$this->tdBuilder,$this->row);
}
}
<?php
function TableFunc($Data)
{
$Table = "<table>" . PHP_EOL;
foreach ($Data as $tags => $array) {
$Table .= "<$tags>" . PHP_EOL;
foreach ($array as $thead) {
$tag=$tags==="tbody"?"td":"th";
$Table .= "<tr>" . PHP_EOL;
if (is_array($thead)) {
foreach ($thead as $theadItem) {
if (is_array($theadItem))
$Table .= "<$tag colspan='$theadItem[1]'>$theadItem[0]</$tag>" . PHP_EOL;
else
$Table .= "<$tag>$theadItem</$tag>" . PHP_EOL;
}
}
$Table .= "</tr>" . PHP_EOL;
}
$Table .= "</$tags>" . PHP_EOL;
}
$Table .= "</table>" . PHP_EOL;
return $Table;
}
$Data = array(
"thead" => [
[["GENEL BİLGİ", 2], ["KALORİMETRE (ISINMA)", 2], ["HESAPLAMA", 2]],
["NO", "AD SOYAD", "FARK", "TUTAR", "OKUMA", "ÖDENECEK"]
],
"tbody"=>array(
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
array("1","MURAT DURAN","100","100.00","10.00","110.00"),
),
"tfoot" => [["NO", "AD SOYAD", "M2", "MAHSUP", "SAYAÇ", "15°", "FARK", "TUTAR", "ORTAK ALAN", "EKSTRA", "MUAFİYET", "OKUMA", "ÖDENECEK"]]
);
echo TableFunc($Data);
I am trying to create the PHP pagination table.. but in below format..
ID: data
Comments: data
Date: data
but now my table is like this:
ID Comments Date
data data data
By any chance anyone could let me know how to change it? .......my code is like this now:
<?
$connection=Mysql_connect('XX','XX','XX');
if(!$connection)
{
echo 'connection is invalid';
}
else
{
Mysql_select_db('XX',$connection);
}
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}
//this part goes after the checking of the $_GET var
$fetch = mysql_query("SELECT * FROM products LIMIT $startrow, 10")or
die(mysql_error());
$num=Mysql_num_rows($fetch);
if($num>0)
{
echo "<table border=0 >";
echo "<tr><td>ID</td><td>Drug</td><td>quantity</td></tr>";
for($i=0;$i<$num;$i++)
{
$row=mysql_fetch_row($fetch);
echo "<tr>";
echo"<td>$row[1]</td>";
echo"<td>$row[2]</td>";
echo"<td>$row[3]</td>";
echo"<td >$row[5]</td>";
echo"</tr>";
}//for
echo"</table>";
}
//now this is the link..
echo 'Next';
$prev = $startrow - 10;
//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0)
echo 'Previous';
?></td>
<td width="331"> </td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
<?php
include("footer.php");
?>
sorry just figure out now..
$row=mysql_fetch_row($fetch);
echo "<tr>";
echo"<td>ID:$row[1]</td>";
echo "</tr>";
echo "<tr>";
echo"<td>Drug:$row[2]</td>"; echo "</tr>"; echo "<tr>";
echo"<td>QTY:$row[3]</td>"; echo "</tr>"; echo "<tr>";
echo"<td >Date:$row[5]</td>"
;echo "</tr>";
echo"</tr>"; echo"<tr height ='20'>";echo"</tr>";
echo"<tr >";echo"</tr>";echo"<tr >";echo"</tr>";
}//for
echo"</table>";
}
Oh, I got it now !
That you can achieve below way:
<table cellpadding="0" cellspacing="0">
<tr>
<th>ID</th>
<th>Comments</th>
<th>Date</th>
</tr>
<?php
if(mysql_num_rows($recordsets) > 0){
foreach ($recordsets as $recordset):
?>
<tr>
<td><?php echo $recordset['id']); ?></td>
<td><?php echo $recordset['comments']); ?></td>
<td><?php echo $recordset['date']); ?></td>
</tr>
<?php
endforeach;
} else {
?>
<tr>
<td colspan="3">No records found !</td>
</tr>
<?php
}
?>
</table>
Here, first row will be your table records header information and then loop through your records result sets.
Hope it helps you !