hi i am making a program in php. it actualy involves two tables from database one is order and other product_details i want that when i select a order i get its product and quantity and respective to that product i find quantity of first raw material reqruired. and then multiply the quantity of 'order' and product table. i have written code its working and not giving me any error but value which it calculates is wrong my code is:

<?php


$con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
 
  $order= ($_POST['order_id']);
  
  $query= " SELECT * FROM `order` WHERE Order_ID='$order'";
  $result=mysql_query($query);
  
  if ($result)
  {
  $row=mysql_fetch_assoc($result);
     if ($row['order_status']=='pending')
	 {
	 $total_quantity=$row['quantity'];
	 echo "$total_quantity";
	 $product=$row['product_id'];
	 
	 $query1="SELECT * FROM product_details WHERE product_name='$product'";
	  $result1=mysql_query($query1) or die(mysql_error());

	  	
		  if ($result1)	 
		  {
		  $row1=mysql_fetch_assoc($result1);
		  $quantity1=$row1['quantity1'];
		  $raw_material1=$row1['raw_material1'];
		  $quantity2=$row1['quantity2'];
		  $raw_material2=$row1['raw_material2'];
		  $quantity3=$row1['quantity3'];
		  $raw_material3=$row1['raw_material3'];
		  $mat1_req=$total_quantity*$quantity1;
		  echo "$mat1_req";
		  }
		  else 
		  {
		  echo "second query failed";
		  }
		 
	 
	 }
	 
	 else 
	 {
	 echo "This order is in process now";
	 }
	}
	else 
	{
	echo "No record found";
	}
	 
?>

What exactly is the output you expect. Try giving a detailed example.

Sidenote: Am not sure how your table structures are, but you should be able to use a single join query, so you won't have to query twice.

can u please tell me how the join statement works? i know the syntax and all that but what is the purpose of that

It's to connect the order with the product details, so you have all info you need in one query result. You could let that query do your multiplication as well. If you use this a lot, you can turn that query into a view. My personal opinion is that a view is much more managable than a query with calculations in source code.

yeah i will try to learn more about views as well.
now i m facing another problem
when i write this code:

$query2="SELECT quantity FROM rpms WHERE product_name='$raw_material1'";
		  $result2=mysql_query($query2) or die(mysql_error());
		  
		  if ($result2)
		    {
			$row2=mysql_fetch_row($result2);
			$quantity2=$row2['quantity'];
			echo "$quantity2";

it gives the following error
Notice: Undefined index: quantity in C:\wamp\www\pras\calculation.php on line 45

You get that notice when you try to use an array with key 'quantity', but it is not set. A possible cause is that your query returns no results. There is no check for that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.