Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete multiple rows from sql query

Posted on 2012-08-28
2
Medium Priority
?
406 Views
Last Modified: 2012-08-28
This code inserts multiple rows of data into a table:

if (!empty($_POST)) {
	foreach ($_POST['record'] as $data) {
		$insertSQL = sprintf(
		"INSERT INTO actualproduction (proddate, tankno, primeactual, tcactual, CHA, COR, REID, ROY, LEE, MANIS, DAN, MON, LES, MAR) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
			$data['prodDate'],
			$data['tankno'],
			$data['primeactual'],
			$data['tcactual'],
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['COR'])) ? $data['COR'] : "No",
			(isset($data['REID'])) ? $data['REID'] : "No",
			(isset($data['ROY'])) ? $data['ROY'] : "No",
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['MANIS'])) ? $data['MANIS'] : "No",
			(isset($data['DAN'])) ? $data['DAN'] : "No",
			(isset($data['MON'])) ? $data['MON'] : "No",
			(isset($data['LES'])) ? $data['LES'] : "No",
			(isset($data['MAR'])) ? $data['MAR'] : "No"
		);
		
		//echo $insertSQL;
		 mysql_select_db($database_pintura, $pintura);
  $Result1 = mysql_query($insertSQL, $pintura) or die(mysql_error());
	}                                            
}

Open in new window


At the same time, I would like to delete data from another table but not sure if this would work?

$deleteSQL = sprintf("DELETE FROM tankbasket WHERE tankno=%s",
                       $data['tankno']);

Open in new window

0
Comment
Question by:jonofat
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 38340401
hmmmmm....

if (!empty($_POST)) {
	foreach ($_POST['record'] as $data) {
		$insertSQL = sprintf(
		"INSERT INTO actualproduction (proddate, tankno, primeactual, tcactual, CHA, COR, REID, ROY, LEE, MANIS, DAN, MON, LES, MAR) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
			$data['prodDate'],
			$data['tankno'],
			$data['primeactual'],
			$data['tcactual'],
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['COR'])) ? $data['COR'] : "No",
			(isset($data['REID'])) ? $data['REID'] : "No",
			(isset($data['ROY'])) ? $data['ROY'] : "No",
			(isset($data['LEE'])) ? $data['LEE'] : "No",
			(isset($data['MANIS'])) ? $data['MANIS'] : "No",
			(isset($data['DAN'])) ? $data['DAN'] : "No",
			(isset($data['MON'])) ? $data['MON'] : "No",
			(isset($data['LES'])) ? $data['LES'] : "No",
			(isset($data['MAR'])) ? $data['MAR'] : "No"
		);
		
		//echo $insertSQL;
		mysql_select_db($database_pintura, $pintura);
                $Result1 = mysql_query($insertSQL, $pintura) or die(mysql_error());

                $deleteSQL = sprintf("DELETE FROM tankbasket WHERE tankno=%s", $data['tankno']);
                mysql_query($deleteSQL , $pintura) or die(mysql_error());

                                  
	}                                            
}

Open in new window

0
 

Author Closing Comment

by:jonofat
ID: 38340424
Schweet!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question