I am trying to group rows with similar ids (order_id in this case) together. I want each group of similar ids in a separate table. My presence query displays all rows in one table. I don't know how to go about it.
This is my code:
<div class='panel panel-body'>
<table class='table table-condensed'>
<thead>
<tr class='cart_menu'>
<td class='price'>Order ID</td>
<td class='price'>Item(s)</td>
<td class='price'>Quantity</td>
</tr>
</thead>
<tbody>
";
$select = "SELECT DISTINCT a.*, b.* FROM shipping_order a JOIN shipping_details b ON b.order_id = a.order_id WHERE user_id = :user_id AND a.order_id = b.order_id";
foreach ($db->query($select, array('user_id' => $id)) AS $items){
echo"
<tr>
<td class='cart_price'>
<h4>{$items['order_id']}</h4>
</td>
<td class='cart_price'>
<h4><a href=''>{$items['item']}</a></h4>
<!-- <p>Web ID: </p> -->
</td>
<td class='cart_price'>
<p>{$items['quantity']}</p>
</td>
</tr>
";
}
echo"
{$items['total']}
</tbody>
</table>
</div>
Related
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.)
I´m creating a school project and in this part I need to present the name of the person associated with this "n_processo" (id).
I have my tablets divided on the database like the printscreen, and I don´t know how to present the name of the person using the foreign key.
Turma Table:
I´m using a functions file, that have the function DBRead12 (that is selecting my "turma" table).
I have the user_especial table that have the names and the stranger key, like on this print.
User_Especial Table:
function DBRead12()
{
$sql="SELECT * FROM turma";
$result=DBExecute($sql);
while($res=mysqli_fetch_assoc($result))
{
$data[]=$res;
}
return $data;
}
<button class="collapsible">Consulta de Turmas</button>
<div class="content">
<br>
<div class="container" align="left">
<div class="well" align="left" style="width:70%">
<?php $admin = DBRead12()?>
<table id="example" class="table table-striped table-bordered" style="width:90%">
<thead>
<tr>
<th>Designação</th>
<th>Tipo</th>
<th>Diretor de Turma</th>
<th>Ano Letivo</th>
</tr>
</thead>
<tbody>
<?php foreach($admin as $cl)
{?>
<tr>
<td align=center><?php echo ($cl['designacao']) ?></td>
<td align=center><?php echo ($cl['tipo']) ?></td>
<td align=center><?php echo ($cl['diretor_turma']) ?></td>
<td align=center><?php echo ($cl['ano_letivo']) ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
In your query, you would use a join statement in order to get data from both tables at once
Example:
$sql="SELECT user_especial.nome, turma.*
FROM turma
LEFT JOIN user_especial ON user_especial.n_processo = turma.director_turma";
$sql="SELECT user_especial.nome as nome, turma.*
FROM turma
LEFT JOIN user_especial ON user_especial.n_processo = turma.director_turma";
This will give you all data from Turma Table and nome from User_Especial Table as nome.
$sql="SELECT user_especial.nome as nome, turma.*
FROM turma
LEFT JOIN user_especial ON user_especial.n_processo = turma.director_turma";
Also you must cut $cl['diretor_turma'] and add $cl['nome'].
So, your tbody will be:
<td align=center><?php echo ($cl['designacao']) ?></td>
<td align=center><?php echo ($cl['tipo']) ?></td>
<td align=center><?php echo ($cl['nome']) ?></td>
<td align=center><?php echo ($cl['ano_letivo']) ?>
</td>
I m struggling to send Each ClientID Information from Database to their specific Email Address.
My training exercise was to use this SQL (See Below) that have 3 different tables that are as follow: Client, Sites, Job_Cards.
Now I have create a SQL that gives me the output that I need. But my problem is based at the fact that 1 clientID may have one or Many SiteID. one SiteID may have one and many Job_Card#.
When I create my PHP Script the Data Displays as follow: Link on a HTML page.
My Question is in 2 Parts:
How can I format the table to Display ONLY 1 ClientID or ClientName with the list of Job#, site name and Description of this single Client?
How may I send an Email to Each of the ClientName Without Duplicate ID. And What php script will be good to use to send Emails to Each Clients?
Here is my PHP Script and My SQL Statment:
$sqlSelect = "SELECT DISTINCT(cl.client_id),
client_name,
DATE(jb.date),
jb.job_number,
jb.repair,
st.site_name
FROM
job_cards jb
INNER JOIN
clients cl ON (cl.client_id = jb.client_id)
LEFT JOIN
sites st on (st.site_id = jb.site_id)
WHERE
jb.completed = 1
AND cl.client_id = jb.client_id
AND jb.date >= DATE_ADD(DATE(NOW()), INTERVAL - 30 DAY)
ORDER BY cl.client_name ASC";
//echo $sqlSelect;
$tresult = mysql_query($sqlSelect);
//die("ss");
//$dataCount = mysql_num_rows($result);
while($userData = mysql_fetch_assoc($tresult)){
if($i%2==0)
$classname = 'evenRow';
else if($i%2==1)
//extract($userData);
?>
</table>
</td>
</tr>
<tr>
<td align='center' height="30" style="font-size:14px;">
<b><?php echo $userData['client_name'];?></b>
</td>
<td align='center'></td>
<td>
<table width='100%' cellpadding= '1' border='0'>
<thead>
<tr>
<td style="font-size:13px; text-align:Left;"><b>Date</b></td>
<td style="font-size:13px; text-align:Left;"><b>Job #</b></td>
<td style="font-size:13px; text-align:left;"><b>Site name</b></td>
<td style="font-size:13px; text-align:left;"><b>Description</b></td>
</tr>
</thead>
<tr class='<?php if(isset($classname)) echo $classname;?>'>
<tr>
<td>
<?php echo mysql_real_escape_string ($userData['DATE(jb.date)']); ?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['job_number']);?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['site_name']);?>
</td>
<td>
<?php echo mysql_real_escape_string($userData['repair']);?>
</td>
</tr>
<?php $i++;
}
?>
</tr>
</table>
<table width='100%' cellpadding= '1' border='1'>
<tr>
</tr>
</table>
Please May Some 1 Help me. I tried What I could But Still I cannot send emails and the Table format doesn't display the way I want.
Thank.
I have a subject and a departments table, Each subject is associated with departments table. I am trying to select all subjects including departments name. The code bellow work perfect but show only two records. Any Help will be appreciated
//Select statement
$selects=$connection->query("SELECT
subjects.id
, subjects.name
, subjects.related_to
, subjects.related_to_sem
, departments.dept
FROM subjects
INNER JOIN departments
ON subjects.related_to = departments.dep_id");
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Sub Id</th>
<th>Subject Name</th>
<th>Related to Department</th>
<th>Related to Semester</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
while($result=$select->fetch_assoc()) {
?>
<tr>
<td><?php echo $result['id']; ?></td>
<td class="center"><?php echo $result['name']; ?></td>
<td class="center"><?php echo $result['dept']; ?></td>
<td class="center"><?php echo $result['related_to_sem']; ?></td>
<td class="center">
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
select
subjects.id,subjects.name,
subjects.related_to,
subjects.related_to_sem,
departments.dept
from
subjects
LEFT OUTER JOIN departments ON subjects.id=departments.dep_id
Please try the following. I think you may have used the wrong fields in the join condition:
SELECT
subjects.id
, subjects.name
, subjects.related_to
, subjects.related_to_sem
, departments.dept
FROM subjects
INNER JOIN departments
/* ON subjects.id = departments.dep_id */
ON subjects.dep_id = departments.id
A "foreign key" in the subjects table for department is much more likely to be subjects.dep_id
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!