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;
}
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
I want to export my code to excel however the header is also dynamic. Here is my code, i need assistance in exporting my data. This code below shows a dynamic table i showed in user view and needs to be exported. The view is:
"title: course/section"
"header: student id | student name | program | term | dynamic date 1 | Remarks (remarks why u are absent) including date 1 | date 2 | Remarks (remarks why u are absent) including date 2 | and so on.."
"table data: 20122222 |pinky webb |computer science | 3 | Absent | With medical certificate | present | no remark | present | no remark | late | no remark | and do on... "
"table data 2: 20122333 |Mane Sharpay|computer science | 3 | Absent | With medical certificate | present | no remark | Late | no remark | late | no remark | and so on... "
and so on...
basically, it shows the student and its attendance per date horizontally with a dynamic header of dates. sorry if im noob hehe but ill give a thumbs up i promise for ur effort
<?php
$query = "SELECT course_id, sections_id from current_att_view inner join professor_tbl on current_att_view.professor_id = professor_tbl.professor_id where professor_live_account = '".$_SESSION['username']."' group by course_id, sections_id";
$result1 = mysqli_query($link, $query);
while ($col1 = mysqli_fetch_array($result1))
{
$reslt;
echo '<h3 class="course-sect">'.$col1[0].'/'.$col1[1].'</h3>';
$qry = "Call Get_Attendance_Course_Section('".$_SESSION['username']."','".$col1[0]."','".$col1[1]."')";
$reslt = mysqli_query($link, $qry);
echo '<table class="table table-bordered">';
echo '<tr>';
if (!$reslt) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
else{
while ($fieldinfo = mysqli_fetch_field($reslt)) {
if($fieldinfo->name != "Course" && $fieldinfo->name != "Section" && $fieldinfo->name != "Course Name" && $fieldinfo->name != "Schedule")
{
echo '<th>';
echo $fieldinfo->name;
echo '</th>';
}
}
echo '</tr>';
while ($rows = mysqli_fetch_array($reslt))
{
for ($i=0; $i < (count($rows)/2); $i++) {
if($i != 3 && $i != 4 && $i != 5 && $i != 6){
echo '<td>';
echo $rows[$i];
echo '</td>';
}
}
echo '</tr>';
}
echo '</table>';
mysqli_next_result($link);
}
}
// $reslt =mysqli_query($link, $qry);
?>
<input type=hidden name=date value='<?php echo date("F d, Y",strtotime($date));?>'>
<input type="hidden" name="outy" value="<?php echo $sql; ?>">
<input type="submit" name="export" value="Export" class="submit" />
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>";
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