How to passed value from looping result to new object using button ?
For example :
I have input text to get order number. The result for Order number 0001 is like this
| Order No | Delivery No | Invoice No | Delivery Date | Action |
=================================================================
| 0001 | D0001 | I0001 | 21-03-2018 |(process button)|
| 0001 | D0002 | I0002 | 21-03-2018 |(process button)|
I have no trouble to display table above, the problem is how to make those process button work ? Process button is to display detail of one invoice. From example above, if i click process button for Invoice I0002 result will be like this
| No. Item | Item Name | Price | Qty | Amount |
================================================
| 0000001 | apple | 5 | 2 | 10 |
and so on..
So far my work for first table
$select_order = "SELECT ORDER_NO, DELI_NO, INV_NO, DELI_DT, AMOUNT FROM ORDER WHERE ORDER_NO = '$text_input_order'";
$exec_order = odbc_exec($connSQL, $select_order);
while(odbc_fetch_row($exec_order))
{
$get_order_no = odbc_result($exec_order, "ORDER_NO");
$get_deli_no = odbc_result($exec_order, "DELI_NO");
$get_inv_no = odbc_result($exec_order, "INV_NO");
$get_deli_dt = odbc_result($exec_order, "DELI_DT");
$get_amount = odbc_result($exec_order, "AMOUNT");
?>
<tr>
<td><? echo $get_order_no;?></td>
<td><? echo $get_deli_no ;?></td>
<td><? echo $get_inv_no ;?></td>
<td><? echo $get_deli_dt ;?></td>
<td><? echo $get_amount ;?></td>
<td><input type="submit" value="proces" name="proces"></td>
</tr>
<?
}
Now I need your help to make second table using process button.
Please made the changes as per your requirements after button click.
<script>
$(function(){
$('button[name=proces]').click(function(){
var id= $(this).attr("id");
//some action here
//ex:
window.location.href="<put your site url>?id="+id;
//or an ajax function
});
});
</script>
<?php
$select_order = "SELECT ORDER_NO, DELI_NO, INV_NO, DELI_DT, AMOUNT FROM
ORDER WHERE ORDER_NO = '$text_input_order'";
$exec_order = odbc_exec($connSQL, $select_order);
while(odbc_fetch_row($exec_order))
{
$get_order_no = odbc_result($exec_order, "ORDER_NO");
$get_deli_no = odbc_result($exec_order, "DELI_NO");
$get_inv_no = odbc_result($exec_order, "INV_NO");
$get_deli_dt = odbc_result($exec_order, "DELI_DT");
$get_amount = odbc_result($exec_order, "AMOUNT");
?>
<tr>
<td><? echo $get_order_no;?></td>
<td><? echo $get_deli_no ;?></td>
<td><? echo $get_inv_no ;?></td>
<td><? echo $get_deli_dt ;?></td>
<td><? echo $get_amount ;?></td>
<td><input type="button" id=".$get_inv_no." value="proces" name="proces"></td>
</tr>
<?
}
Related
I have applied query to show order details in a table according to names and dates. It shows data correct.Right now its displaying data like this:
But now i want my data to be shown in format where i can see all the orders from same client according to date something like this:
ABC ordered on Date:20/05/15
ItemName | Size | Quantity | Color
item1 | XL | 7 | yellow
item2 | L | 3 | pink
item3 | S | 1 | green
XYZ ordered on Date:13/09/15
ItemName | Size | Quantity | Color
item1 | L | 8 | brown
item2 | L | 3 | pink
item3 | S | 4 | green
Any suggestions or help will be appreciable
Code
echo" <table border='3px' bordercolor='#333333' >";
$query="select orders.date,order_detail.quantity,order_detail.price,order_detail.color,order_detail.size,customers.name,products.product_name,products.product_image from order_detail JOIN orders on orders.serial=order_detail.orderid Join customers on customers.serial=orders.customerid Join products on products.productid=order_detail.productid ";
$sql=mysqli_query($con,$query);
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row['name'] ?> </td>
<td><?php echo $row['date'] ?></td>
</tr>
<th>Product</th>
<th>Name & quantity</th>
<th>Color</th>
<th>Price</th>
<th>Size</th>
<tr>
<td><image width="80px" height="90px" src="\images<?php echo $row['product_image'] ?>"/></td>
<td><?php echo $row['product_name']. "*". $row['quantity']?></td>
<td><?php echo $row['color'] ?></td>
<td><?php echo $row['price'] ?></td>
<td><?php echo $row['size'] ?></td>
</tr>
<?php
} }
?>
</table>
Try adding order by this way
$query="select orders.date,order_detail.quantity,
order_detail.price,order_detail.color,
order_detail.size,customers.name,products.product_name,
products.product_image from order_detail
JOIN orders on orders.serial=order_detail.orderid
Join customers on customers.serial=orders.customerid
Join products on products.productid=order_detail.productid
order by orders.date ASC, product.name ASC";
Use Group BY Order_date. If there are multiple orders from same customer Use SUM(quantity) and distinct(Itemname).
I have a table which display list of item names, its classes, item quantities in each class, and total quantity of item for all items. The expected result should look like this:
Item Name | Item Class | Item Quantity | Total Quantity
| 1 | 4 |
A | 2 | 5 | 11
| 3 | 2 |
-------------------------------------------------------
| 1 | 6 |
B | 2 | 3 | 10
| 3 | 1 |
but what I got is like this:
Item Name | Item Class | Item Quantity | Total Quantity
| 1 | 4 |
A | 2 | 5 |
| 3 | 2 |
----------------------------------------
| 1 | 6 |
B | 2 | 3 |
| 3 | 1 | 11 | 10
How to display the total quantity vertically in the same row with its key(item name) and with rowspan. I use array to display results as there are hidden calculation. My code is a bit complicated because of the calculation but lets just ignore the calculation part because it works fine. If you need to understand my calculation, you can view my previous questions from my profile. What I need to fix now is how to display the total quantity correctly.
Here is my code :
<table>
<tr>
<td>Item Name</td>
<td>Item Class</td>
<td>Item Quantity</td>
<td>Total Quantity</td>
</tr>
<?php
$result=mysql_query("SELECT * FROM tblitem");
$classqty=array();
while($row = mysql_fetch_array($result)){
$item=$row['itemName'];
$class=$row['itemClassName'];
if(!isset($classqty[$item][$class]))
{
$classqty[$item][$class] = 0;
}
if(is_null($row['itemLocCheckOut'])){
$classqty[$item][$class] += $row['itemQty'];
}
else{
$classqty[$item][$class] -= $row['itemQty'];
}
}
$sum=array();
foreach($classqty as $k1=>$v1){
foreach($v1 as $k2=>$v2){
if(!isset($sum[$k1])){
$sum[$k1] = $v2;
}
else
{
$sum[$k1] += $v2;
}
?>
<tr>
<td><?php echo $k1;?></td>
<td><?php echo $k2;?></td>
<td><?php echo $v2;?></td>
<?php
} /*close second foreach*/
} /*close first foreach*/
foreach($sum as $name=>$total){
?>
<td><?php echo $total;?></td>
<?php
} /*close foreach for $sum*/
?>
</tr>
</table>
P/S: Please don't suggest me to use SELECT SUM because there is no problem with my calculation and I can't simply use SUM because my code involves multiple series of calculation and the total quantity is based on the result from the calculation. My problem is just on how to display the total quantity result correctly at its place vertically.
Try this...
SELECT *,SUM(IF(item_name='a',itemQuantity,0)) AS itemQuantityA,SUM(IF(item_name='b',itemQuantity,0)) AS itemQuantityB FROM tblitem
Using this you will directly got the sum of item A and B.
and based on your requirement you can edit or customize this query.
Hope this helps.
The HTML needs to be corrected. Have rectified the code. Try it out
<table>
<tr>
<td>Item Name</td>
<td>Item Class</td>
<td>Item Quantity</td>
<td>Total Quantity</td>
</tr>
<?php
$result=mysql_query("SELECT * FROM tblitem");
$classqty=array();
while($row = mysql_fetch_array($result)){
$item=$row['itemName'];
$class=$row['itemClassName'];
if(!isset($classqty[$item][$class]))
{
$classqty[$item][$class] = 0;
}
if(is_null($row['itemLocCheckOut'])){
$classqty[$item][$class] += $row['itemQty'];
}
else{
$classqty[$item][$class] -= $row['itemQty'];
}
}
?>
<tr>
<?php
$sum=array();
foreach($classqty as $k1=>$v1){
?>
<td><?php echo $k1;?></td>
<td>
<table>
<tr>
<?php
foreach($v1 as $k2=>$v2){
if(!isset($sum[$k1])){
$sum[$k1] = $v2;
}
else
{
$sum[$k1] += $v2;
}
?>
<td><?php echo $k2;?></td>
<td><?php echo $v2;?></td>
<?php
} /*close second foreach*/
?>
</tr>
</table>
</td>
<td><?php echo $sum[$k1];?></td>
} /*close first foreach*/
?>
</tr>
</table>
I am trying to display a table by school year using PHP. I it seems not working very well because the school year displays redundantly.
How to simply display it like this?
No | SY | Student ID | Student Name | Gender | Section Code | Subject
-----------------------------------------------------------------------------
2015-2016 SEMESTER 1
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Cocos, Scrappy S. | Male | IT15B | IT15
-----------------------------------------------------------------------------
1 | 2 | 1212211 | asasas, sasas a. | Male | IT15B | IT15
-----------------------------------------------------------------------------
2015-2016 SEMESTER 2
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Cocos, Scrappy S. | Male | IT15B | IT15
-----------------------------------------------------------------------------
1 | 2 | aSAsaSA | dsdsadsad.ssasasas | Male | IT15B | IT15
-----------------------------------------------------------------------------
2016-2017 SEMESTER 1
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Doo, Scooby D. | Male | IT15B | IT15
-----------------------------------------------------------------------------
2016-2017 SEMESTER 2
-----------------------------------------------------------------------------
1 | 2 | 0011941 | Doo, Scooby D. | Male | IT15B | IT15
here's my code:
<tr>
<th>No</th>
<th>SY</th>
<th>Student ID</th>
<th>Student Name</th>
<th>Gender</th>
<th>Section Code</th>
<th>Subject</th>
<th colspan="2">Update</th>
</tr>
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.mi, sts.gender, sub.section_code, sub.subject_name, ets.sem, ets.enroll_num, ets.sy
FROM students sts
JOIN enrollments ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.section_code = ets.section_code)
GROUP BY sts.stud_id, sub.section_code ORDER BY ets.stud_id ASC";
$sql_sel=mysql_query($sql);
$num_rows = mysql_num_rows($sql_sel);
if($num_rows==0)
{
echo "No results found. Please try again";
}
$i=0;
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<th colspan="8"><?php echo $row['sy'];?></th> //this thing here
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['sem'];?></td>
<td><?php echo $row['stud_id'];?></td>
<td width="200"><?php echo $row['lname'].", ".$row['fname']." ".$row['mi'].".";?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['section_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center" width="82"><img src="picture/update.png" /></td>
<!----<td align="center"><img src="picture/delete.png" /></td>-------->
</tr>
<?php
}
?>
First you need to order by year and semester in your query:
$sql= "SELECT sts.stud_id, sts.fname, sts.lname, sts.mi, sts.gender, sub.section_code, sub.subject_name, ets.sem, ets.enroll_num, ets.sy
FROM students sts
JOIN enrollments ets ON(sts.stud_id = ets.stud_id)
JOIN subjects sub ON (sub.section_code = ets.section_code)
GROUP BY sts.stud_id, sub.section_code ORDER BY ets.sy ASC, ets.sem ASC, ets.stud_id ASC";
Then you only write the year row when you detect a change of year:
$i=0;
$yr=null;
while($row=mysql_fetch_array($sql_sel)) //for the first query
{
if ($yr != ($row['sy'] . ' SEMESTER ' . $row['sem'])) {
$yr = $row['sy'] . ' SEMESTER ' . $row['sem'];
print ('<th colspan="8">' . $yr . '</th>');
}
$i++;
$color=($i%2==0)?"lightblue":"white";
?>
<tr bgcolor="<?php echo $color?>">
<td><?php echo $i;?></td>
<td><?php echo $row['sem'];?></td>
<td><?php echo $row['stud_id'];?></td>
<td width="200"><?php echo $row['lname'].", ".$row['fname']." ".$row['mi'].".";?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['section_code'];?></td>
<td><?php echo $row['subject_name'];?></td>
<td align="center" width="82"><img src="picture/update.png" /></td>
<!----<td align="center"><img src="picture/delete.png" /></td>-------->
</tr>
<?php
}
$calistir = mysql_query("select * from cevap INNER JOIN kullanici ON cevap.kullaniciID=kullanici.ID WHERE soruID=1 order by soruID ASC") or die("Hata Olustu!");
while($oku=mysql_fetch_assoc($calistir))
{
?>
<tr>
<td class="tg-031e"><?PHP echo $oku['isim']; ?></td>
<td class="tg-031e"><?PHP echo $oku['soyisim']; ?></td>
<td class="tg-031e"><?PHP echo $oku['cinsiyet']; ?></td>
<td class="tg-031e"><?PHP echo $oku['yas']; ?></td>
<td class="tg-031e"><?PHP echo $oku['cevap']; ?></td>
I have two tables.I used join.I wrote soruID=1 so my web page "SORU 2,SORU3,SORU4,SORU5" columns is null.I need write soruID=2,soruID=3,soruID=4 and soruID=5.How I can do this?
My webpage : altundus.com/ieee.php
Assuming you want a printout like
isim | soyisim | cinsiyet | yas | cevap
I1 | S1 | C1 | Y1 | CV1
I2 | S2 | C2 | Y2 | CV2
I3 | S3 | C3 | Y3 | CV3
etc... Remove the
WHERE soruID=1
from your join query, and make sure you add a closing </tr> tag to the end of the output block. This way, it should loop through each row in your result set, and print out a new table row for each result row.
RESOLVED
Works perfectly! Here is my final code:
<table>
<thead>
<tr>
<?php
$row = mysql_fetch_assoc($result);
foreach ($row as $col => $value) {
echo "<th>";
echo $col;
echo "</th>";
}
?>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
// Write rows
mysql_data_seek($result, 0);
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<?php
foreach($row as $key => $value){
echo "<td>";
echo $value;
echo "</td>";
}
?>
<td><button id="edit_project_button(<?php echo $row['ID']; ?>)" class="edit-project-button edit button" onclick="editproject(<?php echo $row['ID']; ?>)">Edit</button></td>
</tr>
<?php } ?>
</tbody>
</table>
I wish to echo out a HTML table using mysql_fetch functions appropriately. I plan on making a thead to contain the mysql table column names and a tbody to contain the mysql table resultset. The SQL query selects a couple of columns from the table, with default limit set.
The issue: It doesn't seem to print the first row of table data, everything else displays (record #1 missing)
It displays the with column names echo'd within each , it then skips the first record and successfully echo's the 2nd row onward. For example:
| id | firstname | lastname | date_start | date_end | clientid | members | edit |
| 2 | Cal | Clark | 2012-12-12 | 2012-12-12 | 22 | Rob | (edit button) |
| 3 | Rob | Robin | 2012-12-12 | 2012-12-12 | 33 | Cal | (edit button) |
I'm 100% sure that the first record will display from my query in phpmyadmin.
Here is my code:
<table>
<thead>
<tr>
<?php
$row = mysql_fetch_assoc($result);
foreach ($row as $col => $value) {
echo "<th>";
echo $col;
echo "</th>";
}
?>
<th>Edit</th>
</tr>
</thead>
<?php
// Write rows
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><?php echo $row[5]; ?></td>
<td><?php echo $row[6]; ?></td>
<td><button id="edit_project_button(<?php echo $row[0]; ?>)" class="edit-project-button edit button" onclick="editproject(<?php echo $row[0]; ?>)">Edit</button></td>
</tr>
<?php } ?>
</table>
I feel so oblivious right now =/
make a rewind of your data first!!
mysql_data_seek($result, 0);
while ($row = mysql_fetch_array($result)) {
...