Jump to content

Update each record of each table


Baabu

Recommended Posts

what should i do that each record of each table should be update accordingly to the $qty

$tables=array("Charger","Car_Charger","Desk_Charger","Hand_Free","Hand_Covers","Usb_Cables","Card_Read","Usb_Drive");


global $dbserver,$dbuser,$dbpass,$dbname;//same as above

$cxn=ConnectToDb($dbserver,$dbuser,$dbpass,$dbname);//same as above

$qty=0;
$temp_query=0;
for($i=0;$i<sizeof($tables);$i++)
{
	$temp_query=mysql_query("select * from " . $tables[$i]) or die("Error in Final Query: ".mysql_error());;	
	//$temp_result=mysql_fetch_array($temp_query);
	while($temp_result=mysql_fetch_array($temp_query))
	{
	$qty=$temp_result["qty"]-$temp_result["tempqty"];

	if($qty==0)
	{
		//echo "The Stock of ".$tables[$i]."Has finished";
			//		echo "Updating inxx $qty";
		mysql_query("update ". $tables[$i] ." set qty='$qty' where model=model and type=type and code=code")or die ("Error in query orignal update".mysql_error());

	}
	else if($qty>=1)
	{
		mysql_query("update ". $tables[$i] ." set qty='$qty'")or die ("Error in query orignal update".mysql_error());
	}	mysql_query("update ". $tables[$i] ." set tempqty='0'")or die ("Error in query orignal update".mysql_error());


	}
}

well i want that this update query should update each record in the tables individually as this is setting the value of $qty to each row of the selected table with same value

 

 

Link to comment
https://forums.phpfreaks.com/topic/94446-update-each-record-of-each-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.