Jump to content

Can you use php for loops INSIDE of a mySQL query


galvin

Recommended Posts

Can you use php for loops INSIDE of a mySQL query?  Something like this, where $i varies...

 

	$sql = "UPDATE answers SET ";
			for ($i=0;$i<=$total;$i++) {
			echo "answerid$i=$newnum$i,"
                                }
			WHERE something=$something";
	$result = mysql_query($sql, $connection);
	if (!$result) { 
	die("Database query failed: " . mysql_error());
	} else {

	}

 

That isn't inside a query. It's just building a query string in a loop, but from the looks of the query, I'd guess the database isn't normalized. Perhaps if you explain what you want to do, and post the table structure, a better way will present itself.

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.