Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update multiple records in a loop problem...

Status
Not open for further replies.

handle87

Programmer
Jun 27, 2005
53
CA
Hi,

I am having a problem updateing multiple records at a time in a loop... in a MySQL database. I am trying to run an UPDATE query about 5 times in a while loop... I have printed the strings to the screen and am able to run thm directly on the MySQL database... but they do not work in code?

Has anyone had this problem before?

 
Without seeing your code, it's hard to debug your problem.

Ken
 
Here is the code:
Code:
	//MySQL DB CONNECTION
    $DB_MYSQL2 = new DB_MYSQL(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB);
    $DB_MYSQL2->connect();

	//GET ALL THE ACTIVE TESTIMONIALS AND UPDATE THE TESTIMONIAL ORDER
	$strSQL = "SELECT * FROM WebsiteTestimonials WHERE CustomerID = " . $_SESSION['CustomerID'] . " AND WebsiteID = " . $_SESSION['WebsiteID'] . " AND StatusID = 1 ORDER BY OrderID";
	$DB_MYSQL2->open_query("sort", $strSQL);
	while($row_order = $DB_MYSQL2->get_row("sort")){
		if($row_order['OrderID'] < $position){
			$Order = $row_order['OrderID'];
		}elseif($row_order['OrderID'] >= $position){
			$Order = $row_order['OrderID'] + $beforeAfter;
		}
		$strT .= "UPDATE WebsiteTestimonials SET OrderID = " . $Order . " WHERE CustomerID = " . $_SESSION['CustomerID'] . " AND WebsiteID = " . $_SESSION['WebsiteID'] . " AND TestimonialID = " . $row_order['TestimonialID'] . ";";
	}
	$DB_MYSQL2->open_query("update_testimonial", $strT);

A class has been created to to handle the db connection and recordets etc... it works fine for selecting and insert/updateing... but i get get this to work in a loop... if i print out $strT and run it on the MySQL server directly it runs as it should.. any ideas?

 
Thank you for your time... I found out that my coworker had made changes to the class, that I didn't notice and decided not to inform anyone. Sorry to bother for nothing.

Have a good one!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top