How to display multiple values with same ID php - php

I am creating profile of our users and I want to display their children details. Users data is stored in one table and their children data is stored in other.
For one userid there is more than one children detail.
Now, I want to display different children details with same userid (userid is muraqebeenID in children table).
How can I do that?
My DB look like this:
+-------------+-------------+-----------------+
| ID |muraqebeenId | childName |
+-------------+-------------+-----------------+
| 1 | 1 | John Doe |
+-------------+-------------------------------|
| 2 | 1 | Jane Doe |
+-------------|-------------|-----------------+
Here's my code:
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body >
<?php
//connect to DB
$con=mysqli_connect("localhost", "root", "", "idaramsb_newidara");
if ($con-> connect_error)
{
die("Connection Failed". $con-> connect_error);
}
//set page no.
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
//
$schools="";
if (isset($_GET['schoolId'])) {
$schools = "and tblusers.schoolId=".$_GET['schoolId'];
}
$no_of_records_per_page = 5;
if (isset($_GET['records'])) {
$no_of_records_per_page = $_GET['records'];
}
$offset = ($pageno-1) * $no_of_records_per_page;
$sql1="SELECT count(tblusers.userid) as total FROM tblusers
left JOIN tblschools on tblusers.schoolId=tblschools.schoolId
left JOIN jameastd on tblusers.jameaSanad=jameastd.jameasnd
where tblusers.status = 1 ".$schools." and tblusers.liveUser=1 and (tblusers.roleid = 3 or tblusers.roleid = 4 or tblusers.roleid = 17 or tblusers.roleid = 23 or tblusers.roleid = 27 or tblusers.roleid = 24)";
$totalp = 0;
$sql="SELECT tblschools.schoolId, tblschools.schoolName as scnm, jameastd.jameastd, YEAR(tblusers.dobGregorian) as dobGregoria, tblmuraqebeenswot.*, tblroles.roleid, tblroles.name, tblmuraqebeenchildrendetails.*, tblmuraqebeenspousedetails.*, tblusers.* FROM tblusers
left JOIN tblschools on tblusers.schoolId=tblschools.schoolId
left JOIN jameastd on tblusers.jameaSanad=jameastd.jameasnd
left join tblmuraqebeenswot on tblmuraqebeenswot.muraqebeenId=tblusers.userid
left join tblroles on tblroles.roleid=tblusers.roleId
LEFT JOIN tblmuraqebeenspousedetails on tblusers.userid=tblmuraqebeenspousedetails.muraqebeenId
left JOIN tblmuraqebeenchildrendetails on tblusers.userid=tblmuraqebeenchildrendetails.muraqebeenId
where tblusers.liveUser=1 and tblusers.status=1 and (tblusers.roleid = 3 or tblusers.roleid = 4 or tblusers.roleid = 17 or tblusers.roleid = 23 or tblusers.roleid = 27 or tblusers.roleid = 24) GROUP BY tblusers.userid ORDER by tblusers.roleid LIMIT $offset, $no_of_records_per_page";
$result=mysqli_query($con,$sql);
$result1=mysqli_query($con,$sql1);
$resultcheck=mysqli_num_rows($result);
$no_of_pages = ceil($totalp / $no_of_records_per_page);
$date = date('Y');
while ($rows = mysqli_fetch_assoc($result1)){
$totalp = $rows['total'];
}
while ($rows = mysqli_fetch_assoc($result)) {
$roq=$rows['dobGregoria'];
$age=$date - $roq;
echo "
<table border=1 class=headings id=content>
<tr>
<td colspan=3><span class=bold>Name: </span>".$rows['fullName']."</td>
<td width=200px><span class=bold>ITS ID: </span>".$rows['itsId']."</td>
<td rowspan=5 align=center width=160px><img width=140px src=https://www.idaramsb.net/newidara/assets/img/itsphoto.php?itsid=".$rows['itsId']."></td>
</tr>
<tr>
<td width=220px><span class=bold>Mauze: </span>".$rows['scnm']."</td>
<td width=><span class=bold>Muddat: </span></td>
<td><span class=bold>Age: </span>".$age."</td>
<td><span class=bold>Vatan: </span>".$rows['vatan']."</td>
</tr>
<tr>
<td colspan=><span class=bold>Taqarrur Year: </span>".$rows['taqarrurYear']."</td>
<td width=230px><span class=bold>Mobile No.: </span>".$rows['mobile']."</td>
<td colspan=2><span class=bold>Email: </span>".$rows['email']."</td>
</tr>
<tr>
<td><span class=bold>Jamea Farigh Year: </span>".$rows['farighYear']."</td>
<td><span class=bold>Designation: </span>".$rows['name']."</td>
<td colspan=2><span class=bold>Jamea Sanad: </span>".$rows['jameaSanad']."</td>
</tr>
<tr>
<td colspan=2><span class=bold>Qualification: </span>".$rows['education']."</td>
<td colspan=2><span class=bold>Hifz: </span>".$rows['hifzTill']."</td>
</tr>
<tr>
<td colspan=5 height=50px><span class=bold>Past Mawaze:</span></td>
</tr>
<tr>
<td colspan=2 valign=top height=300px><span class=bold>STRENGTHS</span><br>".$rows['strength']."</td>
<td colspan=3 valign=top><span class=bold>WEAKNESSES</span><br>".$rows['weakness']."</td>
</tr>
<tr>
<td colspan=2 valign=top height=300px><span class=bold>OPPURTUNITIES</span><br>".$rows['opportunities']."</td>
<td colspan=3 valign=top><span class=bold>THREATS</span><br>".$rows['threats']."</td>
</tr>
<tr>
<td colspan=5 align=center valign=top height=200px>
<span class=bold>Family Details</span>
<table height= width=1000px border=1>
<tr>
<td width=500px height=10px style='border-top:0.5px dotted;' align=center colspan=2>
<span class=top>Spouse Details</span><br>
</td>
<td width=500px style='border-left:0.5px dotted; border-top:0.5px dotted;'>
<div class=top>Children Details</div>
</td>
</tr>
<tr>
<td colspan=2>
Name: ".$rows['spouseName']."
</td>
<td colspan=2>
Name: ".$rows['childName']."
</td>
</tr>
<tr>
<td>
ITS ID: ".$rows['ejamatNo']."
</td>
<td>
Teaching in MSB?: ".$rows['teachinginMsb']."
</td>
<td>
ITS ID: ".$rows['ejamatNo']."
</td>
</tr>
<tr>
<td colspan=2>
Qualification: ".$rows['qualification']."
</td>
</tr>
<tr>
<td colspan=2>
Computer Skills: ".$rows['computerLiteracy']."
</td>
</tr>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=5 align=center height= ><span class=bold>Personality Traits</span>
<iframe height=689px width=100% src=http://139.59.31.87/horizons/presults.php?itsid=".$rows['itsId']."&testid=1&sw> </iframe>
</td>
</tr>
</table>
<br>";
}
?>
</body>
</html>```

Maybe something like this helps:
SELECT * FROM `childTable` WHERE `muraqebeenId` = 1;

Related

Player Ranks look really bad, how to optimize

I want to make 3 tables with player rankings (I want to add a picture of the class and some other information there), but after taking the working tables and adding information from 1 database, I see that there is a lot of no needed code, which I don't know how to remove ...
I also have a problem, because under the tables I have a gray line that looks terribly ugly.
Thank you for all the help!
<?php include_once "settings.php";
//Ranking
//p1
$query0 = "
SELECT name, honor
FROM players
ORDER BY honor DESC
LIMIT 0,1
";
$result0 = mysqli_query($db, $query0);
$row0 = mysqli_fetch_row($result0);
//p2
$query1 = "
SELECT name, honor
FROM players
ORDER BY honor DESC
LIMIT 1,1
";
$result1 = mysqli_query($db, $query1);
$row1 = mysqli_fetch_row($result1);
//p3
$query2 = "
SELECT name, honor
FROM players
ORDER BY honor DESC
LIMIT 2,1
";
$result2 = mysqli_query($db, $query2);
$row2 = mysqli_fetch_row($result2);
//p4
$query3 = "
SELECT name, honor
FROM players
ORDER BY honor DESC
LIMIT 3,1
";
$result3 = mysqli_query($db, $query3);
$row3 = mysqli_fetch_row($result3);
//p5
$query4 = "
SELECT name, honor
FROM players
ORDER BY honor DESC
LIMIT 4,1
";
$result4 = mysqli_query($db, $query4);
$row4 = mysqli_fetch_row($result4);
//Strona
head("Ranking");
?>
<table style="width: 100%;" border="0">
<tbody>
<tr>
<td style="vertical-align: top; padding-left: 20px;">
<div class="btn_main">
<div class="btn_before"> </div>
<div class="btn_center"><span>Ranking graczy:</span></div>
<div class="btn_after"> </div>
</div>
<br>
<br>
<table align="center">
<tr>
<td>
<table>
<tr>
<td>
<div class="container">
<header>
<div class="btn_main">
<div class="btn_before"> </div>
<div class="btn_center"><span>Easy:</span></div>
<div class="btn_after"> </div>
</div>
</header>
<div class="wrapper">
<table align="center" class="tablea" border="1"
style="border-color:#343434" cellpadding="0"
cellspacing="1">
<thead>
<tr>
<th> P</th>
<th> Gracz</th>
<th> Cześć</th>
</tr>
</thead>
<tbody>
<tr>
<td class="poz">1</td>
<td class="Gracz"><?=$row0[0]?></td>
<td class="Cześć"><?=$row0[1]?></td>
</tr>
<tr>
<td class="poz">2</td>
<td class="Gracz"><?=$row1[0]?></td>
<td class="Cześć"><?=$row1[1]?></td>
</tr>
<tr>
<td class="poz">3</td>
<td class="Gracz"><?=$row2[0]?></td>
<td class="Cześć"><?=$row2[1]?></td>
</tr>
<tr>
<td class="poz">4</td>
<td class="Gracz"><?=$row3[0]?></td>
<td class="Cześć"><?=$row3[1]?></td>
</tr>
<tr>
<td class="poz">5</td>
<td class="Gracz"><?=$row4[0]?></td>
<td class="Cześć"><?=$row4[1]?></td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<div class="container">
<header>
<div class="btn_main">
<div class="btn_before"> </div>
<div class="btn_center"><span>Medium:</span></div>
<div class="btn_after"> </div>
</div>
</header>
<div class="wrapper">
<table align="center" class="tablea" border="1"
style="border-color:#343434" cellpadding="0"
cellspacing="1">
<thead>
<tr>
<th> P</th>
<th> Gracz</th>
<th> Cześć</th>
</tr>
</thead>
<tbody>
<tr>
<td class="poz">1</td>
<td class="Gracz"><?=$row0[0]?></td>
<td class="Cześć"><?=$row0[1]?></td>
</tr>
<tr>
<td class="poz">2</td>
<td class="Gracz"><?=$row1[0]?></td>
<td class="Cześć"><?=$row1[1]?></td>
</tr>
<tr>
<td class="poz">3</td>
<td class="Gracz"><?=$row2[0]?></td>
<td class="Cześć"><?=$row2[1]?></td>
</tr>
<tr>
<td class="poz">4</td>
<td class="Gracz"><?=$row3[0]?></td>
<td class="Cześć"><?=$row3[1]?></td>
</tr>
<tr>
<td class="poz">5</td>
<td class="Gracz"><?=$row4[0]?></td>
<td class="Cześć"><?=$row4[1]?></td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>
<div class="container">
<header>
<div class="btn_main">
<div class="btn_before"> </div>
<div class="btn_center"><span>Hard:</span></div>
<div class="btn_after"> </div>
</div>
</header>
<div class="wrapper">
<table align="center" class="tablea" border="1"
style="border-color:#343434" cellpadding="0"
cellspacing="1">
<thead>
<tr>
<th> P</th>
<th> Gracz</th>
<th> Cześć</th>
</tr>
</thead>
<tbody>
<tr>
<td class="poz">1</td>
<td class="Gracz"><?=$row0[0]?></td>
<td class="Cześć"><?=$row0[1]?></td>
</tr>
<tr>
<td class="poz">2</td>
<td class="Gracz"><?=$row1[0]?></td>
<td class="Cześć"><?=$row1[1]?></td>
</tr>
<tr>
<td class="poz">3</td>
<td class="Gracz"><?=$row2[0]?></td>
<td class="Cześć"><?=$row2[1]?></td>
</tr>
<tr>
<td class="poz">4</td>
<td class="Gracz"><?=$row3[0]?></td>
<td class="Cześć"><?=$row3[1]?></td>
</tr>
<tr>
<td class="poz">5</td>
<td class="Gracz"><?=$row4[0]?></td>
<td class="Cześć"><?=$row4[1]?></td>
</tr>
</tbody>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<BR>
<BR>
</td>
</tr>
</tbody>
</table>
<?php
foot()
?>
Do something like this:
$thisquery = "SELECT name, honor FROM players ORDER BY honor DESC LIMIT 0,4";
$query = mysqli_query($con,$thisquery);
while ($result = mysqli_fetch_array($query)) {
$resultArr[] = array($result["name"],$result["honor"]);
}
echo "<table id='mytable'>";
echo "<tr><td>Position</td><td>name</td><td>honor</td></tr>";
$i=0;
foreach($resultArr[] as $key => $value) {
$i++;
echo "<tr><td class=\"poz\">$i</td>
<td class=\"Gracz\"><?= $value[0] ?></td>
<td class=\"Cześć\"><?= $value[1] ?></td>
</tr>";
}
echo "</table>";
In your CSS you can style like this:
table #mytable td {
background: #eee;
}
(Code not tested, just typed, so beware of typo's.)

Create table with different PHP variables including if statement

I have multiple quires retrieving data from mysql database (multiple tables)
SELECT description FROM table1 As descr WHERE type='MYTYPE'; //this shows description of each product type
SELECT count(id) FROM table2 As tp1 WHERE ACTIVE='Y' AND type=1"); //this is to count records that has this product type =1
SELECT count(id) FROM table2 As tp2 WHERE ACTIVE='Y' AND type=2");
SELECT count(id) FROM table2 As tp3 WHERE ACTIVE='Y' AND type=3");
SELECT count(id) FROM table2 As tp4 WHERE ACTIVE='Y' AND type=4");
What I'm trying to have is a table of each type description, along with count of active products has this type: ignoring the count if the count is 0
Here is modest try, I know it isn't perfect, therefore seeking help here, perhaps different approach will be also helpful, but this doesn't work as it have defining variable which has if statement and also logic is not correct?
$tbl_header = '<tr>
<th width=220px align=left>Type description</th>
<th width=10px align=left>Active products of this type</th>
</tr>';
$tbl_data =
if (tp1>0) {
'<tr>
<td width=220px align=left><font color=#000000>'. {descr[0][0]}.'</td></font>
<td width=10px align=left><font color=#FF0000>.'$tp1.'</td></font>
</tr>';}
if (tp2>0) {
'<tr>
<td width=220px align=left><font color=#000000>'. {descr[1][0]}.'</td></font>
<td width=10px align=left><font color=#FF0000>.'$tp2.'</td></font>
</tr>';}
;
echo "<table> $tbl_header $tbl_data </table>";
Try this method. It should work and you don't have to worry about if statements being in the middle of variable
<table>
<tr>
<th width=220px align=left>Type description</th>
<th width=10px align=left>Active products of this type</th>
</tr>
<?php
if ($tp1 > 0) {
?>
<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>
<?php echo descr[0][0]; ?>
</font>
</td>
<td width=10px align=left>
<font color=#FF0000>
<?php echo $tp1; ?>
</font>
</td>
</tr>
<?php
}
?>
<?php
if ($tp2 > 0) {
?>
<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>
<?php echo descr[1][0]; ?>
</font>
</td>
<td width=10px align=left>
<font color=#FF0000>
<?php echo $tp2; ?>
</font>
</td>
</tr>
<?php
}
?>
</table>
How about this?
<?php
$table_head = "<tr>
<th width=220px align=left>Type description</th>
<th width=10px align=left>Active products of this type</th>
</tr>";
if ($tp1 > 0) {
$table_data_1 = "<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>". descr[0][0] . "</font>
</td>
<td width=10px align=left>
<font color=#FF0000>". $tp1. "</font>
</td>
</tr>";
}
if ($tp2 > 0) {
$table_data_2 = "<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>". descr[1][0] . "</font>
</td>
<td width=10px align=left>
<font color=#FF0000>". $tp2. "</font>
</td>
</tr>";
}
echo "<table> $table_ head $table_data_1 $table_data_2 </table>";
?>
<?php
$table_data = "";
$table_head = "<tr>
<th width=220px align=left>Type description</th>
<th width=10px align=left>Active products of this type</th>
</tr>";
if ($tp1 > 0) {
$table_data = "<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>". descr[0][0] . "</font>
</td>
<td width=10px align=left>
<font color=#FF0000>". $tp1. "</font>
</td>
</tr>";
}
if ($tp2 > 0) {
$table_data .= "<tr>
<td width=2 20 px align=l eft>
< font color=# 000000>". descr[1][0] . "</font>
</td>
<td width=10px align=left>
<font color=#FF0000>". $tp2. "</font>
</td>
</tr>";
}
echo "<table> $table_ head $table_data </table>";
?>

Using login for specified user that are able to delete their own table

This is my database lecturer table name persons
ID FirstName LastName Email
100 alex alex -
102 ali ali -
This is my table user_subject
ID Subject
100 AAA
100 BBB
102 AAA
102 CCC
This is my drop_subject.php
<html>
<head></head>
<body>
<?php
$conn = mysql_connect('localhost','root','password');
mysql_select_db('lecturer');
$query = 'SELECT persons.ID , persons.FirstName , user_subject.subject
FROM persons
INNER JOIN user_subject
ON persons.ID = user_subject.ID
ORDER BY persons.ID';
$result = mysql_query($query) or die(mysql_error());
?>
<table width="400" border="0" align="center" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Drop subject</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Subject</strong></td>
</tr>
<?php while($row = mysql_fetch_assoc($result)) { ?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="data[]" value="<?php echo $row['ID'];?>" /></td>
<td bgcolor="#FFFFFF"> <?php echo $row['ID']; ?> </td>
<td bgcolor="#FFFFFF"> <?php echo $row['subject']; ?> </td>
</tr>
<?php } ?>
<tr>
<td colspan="3" align="left" bgcolor="#FFFFFF"><input type="submit" value="Delete Checked Rows" /></td>
<td colspan="2" align="right" bgcolor="#FFFFFF">Back</td>
</tr>
<?php
if(isset($_POST['data'])) {
$del_query = "DELETE FROM user_subject WHERE No IN (";
foreach($_POST['data'] as $data) {
$del_query .= "'" . (int) $data . "',";
}
$del_query .= "'')";
mysql_query($del_query) or die(mysql_error());
header("Location:" . $_SERVER['PHP_SELF']);
}
mysql_close()
?>
</table>
</form>
</tr>
</table>
</body>
</html>
The problem is when I want to drop subject if I access as Ali I am able to drop the subject of alex.
What I want to do is like when alex access to the drop_subject.php the system only appear his own data which is ID 100 subject AAA and ID 100 subject BBB and he is able to drop his own subject only
What should I use to restrict specific user to access their own database not everyone's database?
The steps taken should be
Able to capture the user ID of the user currently accessing the page;
Filter the result with a WHERE statement together with the ID: WHERE id = <the id of the user>.

Pulling last years data from a table

Hello I'm trying to update this scholarship application box. However when the year changed to 2013 it only displays scholarship applicant info from 2013. I'd like it to display info from 2012. I tried messing around with the date but I cant seem to figure it out. Any help would be greatly appreciated!
<?php
$appYear = date("Y").'-'.(date("Y")+1);
$sql = 'select * from sApplication where studentID = "'.$database->iPrep($_SESSION['ID']).'" AND appYear = "'.$appYear.'" LIMIT 1';
$appID = Scholarship::iFindSQL($sql);
$total = count($appID);
if ($total > 0)
{
$app = array_shift($appID);
}
else
{
$app = 0;
}
?>
<li id="item-2">
<div id="appStatus">
<h3>Application Status</h3>
<blockquote>
<?php if ($app->submitted == ('0000-00-00') || !isset($app->submitted)) { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="50%"><strong>Scholarship<br /> 2013-2014</strong></td>
<td width="50" align="right"> <a style="font-size:16px;" href="welcome.php? app=Scholar">Apply Now</a></td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>References</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td><strong>Scholarship 2012-2013</strong></td>
<td> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
</table>
<?php } else { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="90%"><strong>Scholarship 2013-2014</strong></td>
<td width="10%" align="right"> </td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"><?=dbOutDate($app->submitted)?></td>
</tr>
<tr>
<td><strong>References</strong> </td>
<td align="right"></td>
</tr>
<tr>
<td colspan="2">
<?php
$refs = Reference::iFindSQL("Select * from reference where appID = '".$app->ID."'");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php foreach($refs as $ref) { ?>
<tr> <td> <small><?php if($ref->rType == 'Academic Reference'){ echo 'Academic/Artistic/Professional'; } else { echo 'Community Service'; } ?></small></td> <td align="right"><?=$ref->status?></td></tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td align="right">
<?php
if ($app->complete == 'Approved') { echo 'Approved'; }
if ($app->complete == 'Declined') { echo 'Declined'; }
if ($app->complete == 'Pending') { echo 'Pending'; }
if ($app->complete == 'Incomplete') { echo 'Incomplete'; }
Remove the WHERE clause that limits the year. Use ORDER BY to sort by year, descending.
$sql = 'select * from sApplication
where studentID = "'.$database->iPrep($_SESSION['ID']).
'" ORDER BY appYear DESC LIMIT 1';

Fetch data from mysql via PHP, then group rows with similar column values and count

I basically have this program which fetches orders from a database. My problem is I need to make a report in such a way that the script will get rows with the same column value then count them and display them.
Say Table 'orders'
salesorder family product
1111111 pi_gx af000
1111111 pi_gx af000
1111112 sfng af111
1111113 pi_gx af000
will display in my php page
sales order family qty product
1111111 pi_gx 2 af000
1111112 sfng 1 af111
1111113 pi_gx 1 af000
It counts the quantity of row of the said sales order and displays the quantity, at the same time displays only a single copy of that sales order in my page.
Here's the code:
<body class="printable"><h1 align="center">New Orders Dropped for Product Integration 1X</h1>
<table align="center" width="100%">
<tr>
<td class="labels">Prepared: </td>
<td class="boxed"><?php date_default_timezone_set("Asia/Singapore");$today = date("d/m/y H:i");echo $today; ?></td>
<td class="divider"> </td>
<td class="labels">Time Coverage: </td>
<td class="boxed">12:00 to 2:00</td>
<td class="divider"> </td>
<td class="labels">BirthStamp: </td>
<td class="boxed">5/21/2012</td>
<td class="divider"> </td>
<td class="labels">Saved: </td>
<td class="boxed"><?php echo $today; ?></td>
</tr>
<tr>
<td class="labels">Prepared by (Production): </td>
<td><input type="text" name="preparer" id="preparer" class="boxedPrepared" /></td>
<td class="divider"></td>
<td class="labels">Recorded by (Store): </td>
<td><input type="text" name="recorder" id="recorded" class="boxedPrepared" /></td>
<td class="divider"></td>
<td class="labels">Recorded: </td>
<td class="boxed" colspan="3"><?php echo $today; ?></td>
</tr>
</table>
<br />
<?php
$conn = mysql_connect("localhost", "root", "123456") or die(mysql_error());
mysql_select_db("store") or die(mysql_error());
$sql = mysql_query("SELECT * FROM report ORDER BY salesorder AND masterproduct ASC") or die(mysql_error());
if(mysql_num_rows($sql) == 0) {
echo "<center><b>No ORDER/S in Queue</b></center>";
} else {
echo "
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"data\">
<tr>
<td class=\"dataHeader\">Sales Order</td>
<td class=\"dataHeader\">Sales Order Code</td>
<td class=\"dataHeader\">Family</td>
<td class=\"dataHeader\">Product Code</td>
<td class=\"dataHeader\">Quantity</td>
<td class=\"dataHeader\">Birth Stamp</td>
<td class=\"dataHeader\">Due Date</td>
</tr>
";
while($result = mysql_fetch_array($sql)) {
echo "
<tr>
<td class=\"data\">".$result['salesorder']."</td>
<td class=\"data\"><span class=\"title\">*".$result['salesorder']."*</span><br />".$result['salesorder']."</td>
<td class=\"data\">".$result['family']."</td>
<td class=\"data\"><span class=\"title\">*".$result['masterproduct']."*</span><br />".$result['masterproduct']."</td>
<td class=\"data\">";
//need to echo the value here
echo "</td>
<td class=\"data\">".$result['birthstamp']."</td>
<td class=\"data\"><span class=\"title\">*".$result['duedate']."*</span><br />".$result['duedate']."</td>
</tr>
";
}
echo "</table>";
}
?>
SELECT salesorder, family, product, COUNT() AS qty FROM orders
GROUP BY salesorder;
EDIT: OK, try this on for size:
SELECT r.*, t.qty FROM report r LEFT JOIN
(SELECT salesorder, COUNT() AS qty FROM orders
GROUP BY salesorder) t
ON t.salesorder=r.salesorder
ORDER BY r.salesorder AND r.masterproduct ASC
Try this query:
SELECT
COUNT() AS qty, sales_order, family, products
FROM orders
GROUP BY sales_order
Finally figured it out. Thank you guys for helping. I changed my sql query to this:
$sql = mysql_query("SELECT salesorder, masterproduct, family, birthstamp, duedate, COUNT( * ) AS total FROM report WHERE family = '$family' AND birthstamp BETWEEN '$startDT' AND '$endDT' GROUP BY salesorder, masterproduct, family, duedate ");
and it worked fine!

Categories