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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.