I want to display the total of each column inside the table. Here is my code.
$Tab_info['Width'] = "600" ;
$Col_det = array(
'Name' => array( 'Name',
'Aging Create Order ( <= 5 )',
'Aging Create Order ( > 5 )',
'Total'),
'Size' => array( '200' , '200' , '200' , '100' ),
'Type' => array('sortable-text fd-column-', 'sortable-numeric fd-column-','sortable-numeric fd-column-','sortable-numeric fd-column-'));
$Delim_String = '<table id="Summary" class="sortable-onload-0-normal rowstyle-alt no-arrow" style="width:'.$Tab_info['Width'].'px;background-color:#FFFFFF;">';
$Delim_String .= '<thead><tr>';
for ($Col_count = 0; $Col_count < sizeof($Col_det['Name']) ; $Col_count++) {
$Delim_String .= '<th style="-moz-user-select: none;" class="'.$Col_det['Type'][$Col_count].$Col_count.'" width="'.$Col_det['Size'][$Col_count].'">';
$Delim_String .= '<a title="Sort on '.$Col_det['Name'][$Col_count].'" href="#">'.$Col_det['Name'][$Col_count].'</a>';
$Delim_String .= '</th>';
}
$Delim_String .= '</tr>
</thead>
<tbody>
';
//===================Summary Aging Create Order End===========================
$vSQL = "SELECT u.Nama as Name,
SUM( CASE WHEN t.`AgingCreateOrder` <= 5 THEN 1 ELSE 0 END) 'Aging Less Than or Equal 5',
SUM( CASE WHEN t.`AgingCreateOrder` > 5 THEN 1 ELSE 0 END) 'Aging More Than 5',
COUNT(*) as Total
FROM `oct_usergroup` u
JOIN `oct_tickets` t
ON (t.`Creator_SubType`= u.`Id`)
WHERE
t.Date_Created >= (CURDATE() -INTERVAL 49 DAY)
AND u.Nama IS NOT NULL
AND t.AgingCreateOrder between '1' and '1999'
AND t.Status = 1
GROUP BY u.`Nama`";
$result = mysql_query($vSQL)or die($vSQL."<br/><br/>".mysql_error());
while($row = mysql_fetch_array ($result))
{
$Delim_String .= '
<tr>
<td>'.$row['Name'].'</td>
<td>'.$row['Aging Less Than or Equal 5'].'</td>
<td>'.$row['Aging More Than 5'].'</td>
<td>'.$row['Total'].'</td>
</tr>';
}
$Delim_String .= "</tbody></table>";
$table1 = $Delim_String;
unset($Delim_String);
//===================Summary Aging Update Address start===========================
$Tab_info['Width'] = "600" ;
$Col_det = array(
'Name' => array( 'Name',
'Aging Update Address ( <= 5 )',
'Aging Update Address ( > 5 )',
'Total'),
'Size' => array( '200' , '200' , '200' , '100' ),
'Type' => array('sortable-text fd-column-', 'sortable-numeric fd-column-','sortable-numeric fd-column-','sortable-numeric fd-column-')
);
$Delim_String = '<table id="Summary" class="sortable-onload-0-normal rowstyle-alt no-arrow" style="width:'.$Tab_info['Width'].'px;background-color:#FFFFFF;">
';
$Delim_String .= '<thead>
<tr>
';
for ($Col_count = 0; $Col_count < sizeof($Col_det['Name']) ; $Col_count++) {
$Delim_String .= '
<th style="-moz-user-select: none;" class="'.$Col_det['Type'][$Col_count].$Col_count.'" width="'.$Col_det['Size'][$Col_count].'">';
$Delim_String .= '<a title="Sort on '.$Col_det['Name'][$Col_count].'" href="#">'.$Col_det['Name'][$Col_count].'</a>';
$Delim_String .= '</th>
';
}
$Delim_String .= '</tr>
</thead>
<tbody>
';
I want it to show like this.
====================================================================
| Name | Aging Create Order <=5 | Aging Create Order >5 | Total |
---------------------------------------------------------------------
| Consumer | 159 | 80 | 239 |
---------------------------------------------------------------------
| CSO | 20 | 50 | 70 |
---------------------------------------------------------------------
| Total | 179 | 130 | 309 |
=====================================================================
The last row is the one to be added.
Try with this
$result = mysql_query($vSQL)or die($vSQL."<br/><br/>".mysql_error());
$gt_less = 0;
$gt_more = 0;
$gt_total = 0;
while($row = mysql_fetch_array ($result))
{
$gt_less += $row['Aging Less Than or Equal 5'];
$gt_more += $row['Aging More Than 5'];
$gt_total += $row['Total'];
$Delim_String .= '
<tr>
<td>'.$row['Name'].'</td>
<td>'.$row['Aging Less Than or Equal 5'].'</td>
<td>'.$row['Aging More Than 5'].'</td>
<td>'.$row['Total'].'</td>
</tr>';
}
$Delim_String .= '
<tr>
<td>Grand Total</td>
<td>'.$gt_less.'</td>
<td>'.$gt_more.'</td>
<td>'.$gt_total.'</td>
</tr>';
$Delim_String .= "</tbody></table>";
Related
I am generating a data from the database to html table using php.
I want to output with php condition using the student joining date.
I want to run a condition where you take the j.date and anything before should have - and after should have a 'Pay' button which holds the studentid
+---------+------------+-----+-----+------+------+------+-----+
| Student | J.date | Jan | Feb | Mar | Apr | May | ... |
+---------+------------+-----+-----+------+------+------+-----+
| John | 25-03-2018 | 0 | 0 | 2000 | 0 | 1750 | ... |
| Michael | 10-04-2018 | 0 | 0 | 0 | 5000 | 0 | ... |
+---------+------------+-----+-----+------+------+------+-----+
Something like this
+---------+------------+-----+-----+------+------+------+-----+
| Student | J.date | Jan | Feb | Mar | Apr | May | ... |
+---------+------------+-----+-----+------+------+------+-----+
| John | 25-03-2018 | - | - | 2000 | Pay | 1750 | ... |
| Michael | 10-04-2018 | - | - | - | 5000 | Pay | ... |
+---------+------------+-----+-----+------+------+------+-----+
Updated
The query
<?php
$sqlFees = "SELECT
s.student_id, s.firstname, s.lastname,
c.subject, c.standard, (t.month * c.fee) AS coursefee,
SUM(f.paid) AS paid, MIN(f.paiddate) AS studentstartdate,
SUM(CASE WHEN MONTH(f.paiddate) = 1 THEN f.paid ELSE 0 END) AS MJan,
SUM(CASE WHEN MONTH(f.paiddate) = 2 THEN f.paid ELSE 0 END) AS MFeb,
SUM(CASE WHEN MONTH(f.paiddate) = 3 THEN f.paid ELSE 0 END) AS MMar,
SUM(CASE WHEN MONTH(f.paiddate) = 4 THEN f.paid ELSE 0 END) AS MApr,
SUM(CASE WHEN MONTH(f.paiddate) = 5 THEN f.paid ELSE 0 END) AS MMay,
SUM(CASE WHEN MONTH(f.paiddate) = 6 THEN f.paid ELSE 0 END) AS MJun,
SUM(CASE WHEN MONTH(f.paiddate) = 7 THEN f.paid ELSE 0 END) AS MJul,
SUM(CASE WHEN MONTH(f.paiddate) = 8 THEN f.paid ELSE 0 END) AS MAug,
SUM(CASE WHEN MONTH(f.paiddate) = 9 THEN f.paid ELSE 0 END) AS MSep,
SUM(CASE WHEN MONTH(f.paiddate) = 10 THEN f.paid ELSE 0 END) AS MOct,
SUM(CASE WHEN MONTH(f.paiddate) = 11 THEN f.paid ELSE 0 END) AS MNov,
SUM(CASE WHEN MONTH(f.paiddate) = 12 THEN f.paid ELSE 0 END) AS MDec
FROM
fees f
JOIN enrollments e ON f.enrollmentid = e.enrollment_id
LEFT JOIN courses c ON e.courseid = c.course_id
LEFT JOIN students s ON f.studentid = s.student_id
LEFT JOIN terms t ON e.termid = t.term_id
WHERE
f.paiddate BETWEEN '2018-01-01 00:00:00' AND '2018-12-31 23:59:59'
GROUP BY
f.enrollmentid
ORDER BY NOT EXISTS
(SELECT studentid
FROM fees f
WHERE f.enrollmentid = e.enrollment_id
AND MONTH(f.paiddate) = MONTH(CURDATE())
) DESC
";
$resultFees = mysqli_query($con, $sqlFees);
?>
<table border="1" cellpadding="8" style="border-collapse: collapse;">
<thead>
<th>Name</th>
<th>Subject</th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Paid so far</th>
<th>Start date</th>
</thead>
<?php while($row = mysqli_fetch_assoc($resultFees)) :
$studentId = $row['student_id'];
$studentFName = $row['firstname'];
$studentLName = $row['lastname'];
$studentFullName = $studentFName.' '.$studentLName;
$subject = $row['subject'];
$standard = $row['standard'];
$paid = $row['paid'];
$courseFee = $row['coursefee'];
$studentStartDate = $row['studentstartdate']; // this is the J.date
$monthJan = $row['MJan'];
$monthFeb = $row['MFeb'];
$monthMar = $row['MMar'];
$monthApr = $row['MApr'];
$monthMay = $row['MMay'];
$monthJun = $row['MJun'];
$monthJul = $row['MJul'];
$monthAug = $row['MAug'];
$monthSep = $row['MSep'];
$monthOct = $row['MOct'];
$monthNov = $row['MNov'];
$monthMDec = $row['MDec'];
?>
<tr>
<td><?php echo $studentId.' '.$studentFullName; ?></td>
<td><?php echo $subject.' '.$standard.'<br>'.$courseFee; ?></td>
<td id="0"><?php echo $monthJan; ?></td>
<td id="1"><?php echo $monthFeb; ?></td>
<td id="2"><?php echo $monthMar; ?></td>
<td id="3"><?php echo $monthApr; ?></td>
<td id="4"><?php echo $monthMay; ?></td>
<td id="5"><?php echo $monthJun; ?></td>
<td id="6"><?php echo $monthJul; ?></td>
<td id="7"><?php echo $monthAug; ?></td>
<td id="8"><?php echo $monthSep; ?></td>
<td id="9"><?php echo $monthOct; ?></td>
<td id="10"><?php echo $monthNov; ?></td>
<td id="11"><?php echo $monthMDec; ?></td>
<td><?php echo $paid.'/- '; ?></td>
<td><?php echo $studentStartDate; ?></td>
</tr>
<?php endwhile; ?>
</table>
function formatPay($value, $date, $date2) {
if($value == 0) {
if(strtotime($date) < strtotime($date2) {
$output = '-';
} else {
$output = 'Pay';
}
} else {
$output = $value;
}
return $output;
}
$studentStartDate = $row['studentstartdate']; // this is the J.date
$monthJan = formatPay($row['MJan'],$studentStartDate,'01-01-2018');
$monthFeb = formatPay($row['MFeb'],$studentStartDate,'01-02-2018');
$monthMar = formatPay($row['MMar'],$studentStartDate,'01-03-2018');
$monthApr = formatPay($row['MApr'],$studentStartDate,'01-04-2018');
$monthMay = formatPay($row['MMay'],$studentStartDate,'01-05-2018');
$monthJun = formatPay($row['MJun'],$studentStartDate,'01-06-2018');
$monthJul = formatPay($row['MJul'],$studentStartDate,'01-07-2018');
$monthAug = formatPay($row['MAug'],$studentStartDate,'01-08-2018');
$monthSep = formatPay($row['MSep'],$studentStartDate,'01-09-2018');
$monthOct = formatPay($row['MOct'],$studentStartDate,'01-10-2018');
$monthNov = formatPay($row['MNov'],$studentStartDate,'01-11-2018');
$monthMDec = formatPay($row['MDec'],$studentStartDate,'01-12-2018');
Unless I made a typo somewhere, this should work. Since your code is kind of messy, it's easiest to just make a function that handles this conversion.
I think what you are after is something like this. You could do this in the SQL but since you asked for a php solution, here it is.
I stripped out the query and reformatted some of the html to gain some vertical space.
I also used a button template that you can adjust which ever way you want. I used an array for the months and loop through it and then loop again in the html table cols. The array is not necessary but I prefer to do my calculations outside of my view/template. Also this makes it easier to understand/read.
<?php
$sqlFees = <<<SQL
...
SQL;
$resultFees = mysqli_query($con, $sqlFees);
$buttonTemplate = '<button data-studentid="%s">Pay</button>';
?>
<table border="1" cellpadding="8" style="border-collapse: collapse;">
<thead>
<th>Name</th><th>Subject</th>
<th>Jan</th><th>Feb</th><th>Mar</th><th>Apr</th><th>May</th>
<th>Jun</th><th>Jul</th><th>Aug</th><th>Sep</th><th>Oct</th><th>Nov</th><th>Dec</th>
<th>Paid so far</th>
<th>Start date</th>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($resultFees)) :
$button = sprintf($buttonTemplate, $row['student_id']);
$joinDate = \DateTime::createFromFormat('Y-m-d H:i:s', $row['studentstartdate']);
$joinMonth = $joinDate->format('m');
$courseFee = $row['coursefee'];
$payments = [ $row['MJan'], $row['MFeb'], $row['MMar'], $row['MApr'], $row['MMay'],
$row['MJun'], $row['MJul'], $row['MAug'], $row['MSep'], $row['MOct'], $row['MNov'], $row['MDec']];
$buttons = [];
foreach ($payments as $month => $paid) {
if($joinMonth > ($month + 1)) {
$buttons[$month] = '-';
continue;
}
if(0 === (int)$paid) {
$buttons[$month] = $button;
continue;
}
$buttons[$month] = $paid;
}
?>
<tr>
<td><?= $row['firstname'] . ' ' . $row['lastname']; ?></td>
<td><?= $row['subject'] . ' ' . $row['standard'] . '<br>' . $row['paid']; ?></td>
<?php foreach($buttons as $mon => $but): ?>
<td id="<?= $mon; ?>"><?= $but; ?></td>
<?php endforeach; ?>
<td><?= $row['paid']; ?></td>
<td><?= $row['studentstartdate']; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
The important bit is :
foreach ($payments as $month => $paid) {
if($joinMonth > ($month + 1)) {
$buttons[$month] = '-';
continue;
}
if(0 === (int)$paid) {
$buttons[$month] = $button;
continue;
}
$buttons[$month] = $paid;
}
In the first if, it checks if the student was actually joined, (and since i used an array index, i need to add one to the month).
In the second if, it checks to see if there was no payment made and adds the button.
And by default it shows the value paid.
One thing to note is that you could do this in an if-elseif-else structure, but i'd like to show some different way of addressing this, and this way is also slightly faster (micro optimizations)
your question is unclear but i'll give a try.
You could do something like this :
$date = date_create_from_format('d-m-Y', $j.date);
then in your table :
<?= $date->format('m') < $yourMonth ? '-' : $date->format('m') == $yourMonth ? $yourNumber : $date->format('m') +1 == $yourMonth ? 'Pay' : $yourNumber ?>
Hope this will be helpful
Below is products table :
id | mid | wgh | remark| remkok |
1 3 1.5 r3ok 1
2 2 1.5 0
3 2 0.6 nice 0
4 1 1.2 okh 0
5 4 1.5 bye 0
6 4 2.4 okby 0
7 3 3.0 oknice 1
I want to display remark below tr of group by mid..like below
mid wgh
3 1.5
3.0
remarks : r3ok, oknice
4 1.5
2.4
remarks : bye, okby
2 1.5
0.6
remarks : , nice
1 1.2
remarks : okh
What I have tried as below :
$pid= null;
while($row = mysql_fetch_array($result))
{
$rowpkts = $row['mid'];
echo "<tr class=\"undercl\">";
if($rowpkts != $pid){
echo'<td align="center" valign="top">'.$row["mid"].'</td>';
}else{
echo'<td align="center" valign="top"></td>';
}
echo'<td align="center" valign="top">'.$row["wgh"].'</td>';
echo "</tr>";
// what i tried to build for remarks as below
$remsql = "SELECT mid as onu , GROUP_CONCAT(`remark` ORDER BY `id` ASC SEPARATOR ', ') AS plrmks
FROM products WHERE 1=1 GROUP BY `mid`";
$fetchremk = mysql_query($remsql);
$rowresults = mysql_fetch_array($fetchremk);
if($rowresults['onu'] == $pid ){
echo"<tr style='border-style:underline;'>";
echo'<td align="center" align="top">'.$rowresults["plrmks"].'</td>';
echo"</tr>";
}
}
$pid = $rowpkts;
}
But remarks is not coming proper below tr... it means its not display below mid=3 or mid=1.
Any other way,that would help me.
Add appropriate colspan as required and do not do center align.
Try below code
while($row = mysql_fetch_array($result))
{
$rowpkts = $row['mid'];
echo "<tr class=\"undercl\">";
if($rowpkts != $pid){
echo'<td align="center" valign="top">'.$row["mid"].'</td>';
}else{
echo'<td align="center" valign="top"></td>';
}
echo'<td align="center" valign="top">'.$row["wgh"].'</td>';
echo '</tr>';
$remsql = "SELECT mid as onu , GROUP_CONCAT(`remark` ORDER BY `id` ASC SEPARATOR ', ') AS plrmks
FROM products WHERE `remkok`= 1 GROUP BY `mid`";
$fetchremk = mysql_query($remsql);
$rowresults = mysql_fetch_array($fetchremk);
if($rowresults['onu'] == $pid ){
echo"<tr><td colspan ='?'> Remarks : ";
echo $rowresults["plrmks"];
echo "</td></tr>";
}
$pid = $rowpkts;
}
Product_Package
------------------------------------------------------------------------------------
code size price image description
------------------------------------------------------------------------------------
0001 2kg 20 0012.jpg description0012
0001 4kg 40 0014.jpg description0014
0001 6kg 60 0016.jpg description0016
0001 8kg 80 0018.jpg description0018
0002 3kg 30 0023.jpg description0023
0002 5kg 50 0025.jpg description0025
0002 7kg 70 0027.jpg description0027
0002 8kg 80 0028.jpg description0028
0003 1kg 10 0031.jpg description0031
0003 2kg 20 0032.jpg description0032
0003 6kg 60 0036.jpg description0036
0003 9kg 90 0039.jpg description0039
Product_List
------------------------------
code name
------------------------------
0001 FR
0002 GR
0003 WR
0004 BR
And then I try to get the data with this code
$results = $mysqli->query
("
SELECT product_package.size,
product_package.price,
product_package.description,
product_package.image,
product_list.code,
product_list.name
FROM product_package
LEFT JOIN product_list ON product_list.code = product_package.code"
);
$orders = array();
$html = '';
if ($results) {
while($obj = $results->fetch_object()) {
$orders[$obj->code][$obj->name] = array(
'name' => $obj->name,
'price' => $obj->price,
'size' => $obj->size,
'description' => $obj->description,
'image' => $obj->image);
}
$html .= '<table width="70%"><tr>';
$html .= '<td>id</td>';
$html .= '<td>name</td>';
$html .= '<td>package_size</td>';
$html .= '<td>price</td>';
$html .= '<td>image</td>';
foreach ($orders AS $order_id => $order) {
$orderCount = count($order);
$html .= '<tbody>';
$html .= '<tr>';
$html .= '<td rowspan="' . count($order) . '">' . $order_id . '</td>';
$row = 1;
foreach ($order AS $item => $data) {
if ($row > 1) { $html .= '</tr><tr>'; }
$html .= '<td>' . $item . '</td>';
$html .= '<td>' . $data['size'] . '</td>';
$html .= '<td>' . $data['price'] . '</td>';
$html .= '<td>'. $data['description'] . '</td>';
$html .= '<td>' . $data['image'] . '</td>';
$row++;
}
}
$html .= '</tr>';
$html .= '<tbody>';
$html .= '</table>';
}
echo $html;
What I want the result is like this:
------------------------------------------------------------------------------------
code name package size price image
------------------------------------------------------------------------------------
2kg 20 0012.jpg
0001 FR 4kg 40 0014.jpg
6kg 60 0016.jpg
8kg 80 0018.jpg
3kg 30 0023.jpg
0002 GR 5kg 50 0025.jpg
7kg 70 0027.jpg
8kg 80 0028.jpg
1kg 10 0031.jpg
0003 WR 2kg 20 0032.jpg
6kg 60 0036.jpg
9kg 90 0039.jpg
However the php code above give me this result:
------------------------------------------------------------------------------------
id name package_size price descripttion image
------------------------------------------------------------------------------------
0001 FR 2kg 20 description0012 0012.jpg
0002 GR 4kg 40 description0024 0024.jpg
0003 WR 6kg 60 description0036 0036.jpg
0004 BR 8kg 80 description0048 0048.jpg
90 description0039 0039.jpg
Can anybody help me out with this? Thanks in advance.
You need to use group by and group concate functions of mysql please refer below sample query.
select id,group_concat(package_size) as package, group_concat(price) as Price, group_concat(image) as Image from mytbl group by code
I am trying to create reports based on data from a log in the database that looks like:
id | student | type | marks
1 23494 CAT1 50
2 23495 CAT1 20
3 23494 CAT2 35
4 23495 MIDTERM 40
My select statement so far looks like this:
$res = #mysqli_query ($dbc, "SELECT id, student, type, GROUP_CONCAT(marks) AS mark, GROUP_CONCAT(type) AS types FROM log WHERE class = '1' AND term = '2' GROUP BY student DESC");
// Fetch and print all the records....<br>
while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
echo '<tr>
<td align="left">'. $row['student'] .'</td>';
//$exams = split(",", $row['exams']); // 4,3,1,2
$marks = split(",", $row['mark']); // 10,20,40,50
foreach( $marks as $mark ) {
echo '
<td align="left">' . $mark . '</td>
';
}
echo '</tr>';
} //End LOOP
//Then i end table
So far the data displays like so:
STUDENT | CAT1 | CAT2 | MIDTERM
23494 50 35
23495 20 40
The problem is that the code is not arranging 'marks' according to 'type' (look at MIDTERM output for id 4 and corresponding display).
Question:
How do i display the results by student, followed by marks in the appropriate cell/group like so:?
STUDENT | CAT1 | CAT2 | MIDTERM
23494 50 35
23495 20 40
Thanks in Advance Guys.
First, try to keep logic away from layout. It's generally good practice to first gather the data you need, and then display it.
Using GROUP_CONCAT can make things more complicated, since you do not know how many results you will get for each student, nor will you be able to easily identify which marks are of what type.
With that in mind I've created a solution. You'll still need to extend the query of course.
$query = 'SELECT student, type, marks FROM log';
$res = mysqli_query($query);
$studentMarks = array();
while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC))
{
$studentMarks[$row['student']][$row['type']] = $row['marks'];
}
// Now $studentMarks should look like:
// $studentMarks = array(
// 23494 => array('CAT1' => 50, 'CAT2' => 35)
// , 23495 => array('CAT1' => 20, 'MIDTERM' => 40)
// );
echo '<table><thead><tr>';
echo '<td>Student</td><td>CAT1</td><td>CAT2</td><td>MIDTERM</td>';
echo '</tr></thead><tbody>';
foreach($studentMarks as $studentId => $marks)
{
echo '<tr>';
echo '<td>', $studentId, '</td>';
echo '<td>', (isset($marks['CAT1']) ? $marks['CAT1'] : ' '), '</td>';
echo '<td>', (isset($marks['CAT2']) ? $marks['CAT2'] : ' '), '</td>';
echo '<td>', (isset($marks['MIDTERM']) ? $marks['MIDTERM'] : ' '), '</td>';
echo '</tr>';
}
echo '</tbody></table>';
I have 2 table.
Table1 "Order"
orderid - customer_id
1001 - 1234
Table2 "Items"
no - orderid - items_code
1 - 1001 - 100
2 - 1001 - 200
3 - 1001 - 300
how to get results as below (in php):
Order # Items Customer ID
_________________________________________
1001 100, 200, 300 1234
_________________________________________
1002 400, 500, 600 1210
_________________________________________
1003 321, 654, 987 1256
_________________________________________
This is my previous coding:
<?
include("cat-config.php");
$resultdata=mysql_query("
(SELECT * FROM Order LIMIT 10)
");
echo "<table width=\"100%\" border=\"0\">
<tr>
<td>Order #</td>
<td>Items</td>
<td>Customer ID</td>
</tr>";
while($row=mysql_fetch_assoc($resultdata)){
echo "
<tr>
<td>$row[OrderID]</td>
<td>
**(I want loops items data on table "items": 100, 200,300 here)
</td>
<td>$row[CustomerID</td>
</tr>
";
}
mysql_close();
?>
$orders = array( 1001, 1002, 1003 );
for ( $i = 0; $i < count( $orders ); $i++ )
{
$items = getItemsForOrderId( $orders[$i] ); // SQL query or something
for ( $j = 0; $j < count( $items ); $j++ )
{
echo 'Order #' . $orders[$i] . ', Item ' . $items[$j];
}
}
Format to wanted output, and adjust to get the data correctly.
Update based on the changed question:
This could be one way to do it:
<?php
include 'cat-config.php';
$resultdata = mysql_query( 'SELECT * FROM Order LIMIT 10' );
echo "<table width=\"100%\" border=\"0\">
<tr>
<td>Order #</td>
<td>Items</td>
<td>Customer ID</td>
</tr>";
while ( $orderRow = mysql_fetch_assoc( $resultData ) )
{
echo " <tr>\n <td>" . $orderRow['orderid'] . "</td>\n";
echo " <td>";
$itemData = mysql_query( 'SELECT * FROM Items WHERE orderid = ' . $orderRow['orderid'] );
while ( $itemRow = mysql_fetch_assoc( $itemData ) )
{
echo $itemRow['items_code'] . ', ';
}
echo "</td>\n <td>" . $orderRow['customer_id'] . "</td>\n </tr>\n";
}
Easiest is to run it as 2 seperate queries:
SELECT * FROM Order
And while looping through results:
X = OrderID
SELECT * FROM Items WHERE OrderId = X