galvin Posted February 18, 2011 Share Posted February 18, 2011 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 { } Link to comment https://forums.phpfreaks.com/topic/228042-can-you-use-php-for-loops-inside-of-a-mysql-query/ Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2011 Share Posted February 18, 2011 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. Link to comment https://forums.phpfreaks.com/topic/228042-can-you-use-php-for-loops-inside-of-a-mysql-query/#findComment-1175900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.