PHP select From Mysql - 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.

Related

How to passed value from looping result to new object?

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>
<?
}

Order details display ORDER BY date and name

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).

How to display array value vertically in table based on key using PHP?

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>

How to display tables by school year and semester using php?

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
}

serial number on the table in codeigniter pagination libarary

I have problems when numbering the tables using CodeIgniter framework with libraary pagination. below are the table..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 12345 | udin | A | A1 |
+------------------------------------------+
| | | | B | B1 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
| 2 | 54321 | JHON | B | B2 |
+------------------------------------------+
| | | | C | C1 |
+------------------------------------------+
the issue is on the next page in the table below..
+------------------------------------------+
| num| NIP | Name | Category | Type |
+------------------------------------------+
| 1 | 54321 | JHON | F | F2 |
+------------------------------------------+
| | | | G | G3 |
+------------------------------------------+
| | | | G | G4 |
+------------------------------------------+
| | | | I | I3 |
+------------------------------------------+
| | | | J | J1 |
+------------------------------------------+
I want the next page numbering sequential numbering starting from the end of the previous value. Supposedly in figure 2 numbering number "2" instead of "1".
code in the controller:
$this->load->library('pagination');
$data['judul'] = 'Report Data Attachment';
$start_row = $this->uri->segment(3);
$per_page = 10;
if (trim($this->uri->segment(3)) == '')
{
$start_row = '0';
}
$config['base_url'] = base_url().'report/index/';
$config['total_rows'] = $this->lampiran_m->lampiran_karyawan_semua_page_conter()->num_rows();
//$config['uri_segment'] = '3';
$config['per_page'] = $per_page;
$config['full_tag_open'] = '<p class="page">';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['lampiran'] = $this->lampiran_m->lampiran_karyawan_semua_page($start_row,','.$per_page);
$data['no'] = '';
$data['last'] = '';
$this->template->display('tabel_report',$data);
and code in my Model :
public function lampiran_karyawan_semua_page($offset='',$limit='')
{
$qry = "select distinct lampiran.id_category,name_category,tipe,lampiran.nip from lampiran
left join employee on (lampiran.nip = employee.nip)
left join category on (lampiran.id_category=category.id_category) where lampiran.id_category = category.id_category and lampiran.nip=employee.nip order by lampiran.nip desc limit $offset $limit";
return $this->db->query($qry);
}
and this code in view :
<table border="1" width="100%" cellpadding="0" cellspacing="0" id="product-table" >
<tr>
<th class="table-header-repeat line-left minwidth-1"> No</th>
<th class="table-header-repeat line-left minwidth-1"> NIP</th>
<th class="table-header-repeat line-left minwidth-1"> Name</th>
<th class="table-header-repeat line-left minwidth-1"> Category Attachment</th>
<th class="table-header-repeat line-left minwidth-1">Type Attachment </th>
<th class="table-header-repeat line-left minwidth-1">Page </th>
</tr>
<?php
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
I hope someone can help me on this issue .. thanks
before foreach you have to add
$no = $this->uri->segment(3)+1;
No
NIP
Name
Category Attachment
Type Attachment
Page
</tr>
<?php
//before foreach you have to add
$no = $this->uri->segment(3)+1;
foreach($lampiran->result_array() as $k) {
$now=$k['nip'];
if($last!=$now ) {
$no++;
echo "<tr><td>$no</td><td>$k[nip]</td><td>".$this->employee_m->get($k['nip'])->nama."</td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}else{
echo "<tr><td> </td><td> </td><td> </td><td>$k[name_category]</td><td>$k[tipe]</td><td>"; ?>
<?php foreach($this->lampiran_m->conter_tabel_semua($k['id_category'],$k['tipe'],$k['nip'])->result() as $row) :?>
<?php echo $row->nilai;?>
<?php endforeach;
echo "</td></tr>";
}
$last = $k['nip'];
}
?>
<tr><td colspan="5" style="text-align: center;"><b>Jumlah Total</b></td><td>
<?php foreach($this->lampiran_m->jumlah_semua_lampiran()->result() as $row) :?>
<?php echo "<b>$row->jumlah</b>";?>
<?php endforeach; ?>
</td></tr>
</table>
please put below line before foreach statement
$currentffset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$slno_start = (($currentffset / $per_page) * per_page) + 1;
after that use $slno_start as serial number for each item inside foreach at last line of foreach just increment it
$slno_start++;
Minor improvement from above answers.Thanks both of u guys
$count =$this->uri->segment(3)+1;
foreach($records as $rec){echo $count; $count++;}

Categories