3 Replies - 297 Views - Last Post: 08 November 2017 - 06:10 AM Rate Topic: -----

#1 sunshinee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-October 17

only one data is display

Posted 08 November 2017 - 01:17 AM

Something error in my cooding and i have been trying to fix it.
the problem is only one data is display. the data cant display all.

<?php
		  	$i = 0;

include("db.php");
if(isset($_GET['view_st'])){
	
	$product_id = $_GET['view_st'];

	$get_st = "SELECT * from stok_kategori where product_id='$product_id' ";
	
	$run_st = mysqli_query($con, $get_st);
		

	while($row_st=mysqli_fetch_array($run_st)){
			$stok_name = $row_st['stok_name'];
			$product_id = $row_st['product_id'];
			
	}

$stok="SELECT * FROM stok_data WHERE product_id='$product_id'";
$run_stok=mysql_query($stok);
while($row=mysql_fetch_array($run_stok))
{
$product_id=$row['product_id'];	
$date=$row['date'];
$no_kad=$row['no_kad'];
$in_out=$row['in_out'];
$i++;
}

$sql=mysql_query("SELECT * FROM stok_in where product_id='$product_id'");
while($row=mysql_fetch_array($sql))
{		
$in_qty=$row['in_qty'];
$in_unit_price=$row['in_unit_price'];	
$i++;	
}

$sql=mysql_query("SELECT * FROM stok_outcome where product_id='$product_id'");
while($row=mysql_fetch_array($sql))
{		
$in_total = $row['in_total'];
$out_total 	 = $row['out_total'];
$blnce_qty  = $row['blnce_qty'];
$blnce_total  = $row['blnce_total'];
$i++;			
}
$sql=mysql_query("SELECT * FROM stok_out where product_id='$product_id'");
while($row=mysql_fetch_array($sql))
{		
$out_qty=$row['out_qty'];
$i++;	
}
	echo"<table width='1040' align='center' bgcolor='white' cellpadding='6px' border='1'>
		 <tr align='center' bgcolor='#00CCFF' >
		 <td colspan='10' bgcolor='white' align='center' ><h3 class='l'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Perihal Stok: $stok_name  
	</h3>
			           
</br><a class='shopBtn' align='center' ><a href='admin/lapor1.php?product_id=$product_id'>>> PRINT <<</a></br>
<a class='shopBtn' align='center' ><a href='daftar.php?product_id=$product_id'>>> Pengeluaran/Terimaan <<</a> </br>
</td>
<tr>
    <td width='56' rowspan='2'  bgcolor='#66CC33'>Tarikh</td>
    <td width='70' rowspan='2'  bgcolor='#66CC33'>No.Kad</td>
    <td width='129' rowspan='2'  bgcolor='#66CC33'>Terimaan Daripada/Keluaran Daripada</td>
    <td height='34' colspan='3'  bgcolor='#66CC33'><div align='center'>Terimaan</div></td>
    <td colspan='2' bgcolor='#66CC33'><div align='center'  >Keluaran</div></td>
    <td width='56' rowspan='2'  bgcolor='#66CC33'>Baki Kuantiti</td>
    <td width='58' rowspan='2'  bgcolor='#66CC33'>Baki Jumlah</td>
	<td width='58' rowspan='2'  bgcolor='#66CC33'>&nbsp;</td>
  </tr>
  
  </tr>
    <td width='61' bgcolor='#66CC33'><div align='center' >Kuantiti</div></td>
    <td width='81' bgcolor='#66CC33'><div align='center'  >Harga/Unit</div></td>
    <td width='84' bgcolor='#66CC33'><div align='center'  >Jumlah (RM) </div></td>
    <td width='68' bgcolor='#66CC33'><div align='center'  >Kuantiti</div></td>
    <td width='83' bgcolor='#66CC33'><div align='center'  >Jumlah (RM)</div></td>
  </tr>";

$stk = "SELECT * FROM stok_data WHERE  product_id='$product_id'";
$run_stk=mysql_query($stk);
$in_total=0;
$out_total=0;

while($row2=mysql_fetch_array($run_stk))
{

$date=$row2['date'];
$no_kad=$row2['no_kad'];
$in_out=$row2['in_out'];
}

$sql=mysql_query("SELECT * FROM stok_in where product_id='$product_id'");
while($row4=mysql_fetch_array($sql))
	{
		
		$in_qty=$row4['in_qty'];
		$in_unit_price=$row4['in_unit_price'];
		
	} 
$sql=mysql_query("SELECT * FROM stok_out where product_id='$product_id'");
while($row=mysql_fetch_array($sql))
	{
		
		$out_qty=$row['out_qty'];	
	}   

$sql=mysql_query("SELECT * FROM stok_outcome where product_id='$product_id'");
while($rows=mysql_fetch_array($sql))
	{
		$in_total = $rows['in_total'];
		$out_total 	 = $rows['out_total'];
		$blnce_qty  = $rows['blnce_qty'];
		$blnce_total  = $rows['blnce_total'];	
	}   

$in_total=($in_qty*$in_unit_price) ;
$out_total=($out_qty*$in_unit_price); 
$blnce_qty=$in_qty+$in_qty;
$blnce_total=$in_total;
$blnce_total=$in_total-$out_qty;
	
		echo "
		<tr>
    <td align='center'>$date</td>
    <td align='center'>$no_kad</td>
    <td align='center'>$in_out</td>
    <td align='center' style='color:red'>$in_qty</td>
    <td align='center' style='color:red'>$in_unit_price</td>
    <td align='center' style='color:red'>$in_total</td>
    <td align='center'><strong>$out_qty</strong></td>
    <td align='center' ><strong>$out_total</strong></td>
    <td align='center'>$blnce_qty</td>
	<td align='center'>$blnce_total</td>   
	<td align='center'><a href='edit_stokk.php?edit_sk=<?php echo $product_id; ?>'>Ubah</a></td>
  </tr>
	
	
";
	}
      echo "
	 </br> </table>
	 
	  <p>&nbsp;</p>
	
							<p>&nbsp;</p>";


	
?>



Is This A Good Question/Topic? 0
  • +

Replies To: only one data is display

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3715
  • View blog
  • Posts: 13,474
  • Joined: 08-August 08

Re: only one data is display

Posted 08 November 2017 - 01:31 AM

Deprecated MySQL functions are simpler to use (not counting all the sanitizing you need to add) than PDO or MySQLi prepared statements, but far less secure. That's why they've been deprecated. If you're just learning PHP you should start with
http://www.dreaminco...duction-to-pdo/
or
http://php.net/manua...-statements.php
When dealing with old code that uses deprecated MySQL functions you should replace them if possible. If it's not possible, your experience with PDO or MySQLi will benefit you when dealing with MySQL functions.

The MySQL extension is dead. DO NOT USE IT.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: only one data is display

Posted 08 November 2017 - 02:11 AM

Do not use a meaningless title, "Another PHP Question". I have changed it for you.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: only one data is display

Posted 08 November 2017 - 06:10 AM

Aside from being ancient and obsolete code (and mixing the mysql and mysqli extension libraries) you should definitely not be executing 8 or 9 separate queries against a database in a single page. Use joins and, as far as possible, gather the information you need from a single query (and only execute this query when you determine that you need to).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1