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 { } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.