cliftonbazaar Posted January 16, 2010 Share Posted January 16, 2010 This is my code at the moment as I have simply gone the long way around to complete this task, but surely there has to be a quicker way with a loop - I attempted several methods of trying to get a loop going but after 2 hours I gave up and went the long way Please note that I am learning PHP so please go easy //Update the database for the players if($playingTeam=="home") { $sql = "UPDATE matches SET home1='{$playerArray1}', home2='{$playerArray2}', home3='{$playerArray3}', home4='{$battingArray4}', home5='{$playerArray5}', home6='{$playerArray6}', home7='{$playerArray7}', home8='{$playerArray8}', home9='{$playerArray9}', home10='{$playerArray10}', home11='{$playerArray11}' WHERE matchID='{$match['matchID']}'"; } else { $sql = "UPDATE matches SET away1='{$playerArray1}', away2='{$playerArray2}', away3='{$playerArray3}', away4='{$playerArray4}', away5='{$playerArray5}', away6='{$playerArray6}', away7='{$playerArray7}', away8='{$playerArray8}', away9='{$playerArray9}', away10='{$playerArray10}', away11='{$playerArray11}' WHERE matchID='{$match['matchID']}'"; } if(!mysql_query($sql,$sqldb)) die('Error: ' . mysql_error()); //Update the record, if there is an error then show it Quote Link to comment https://forums.phpfreaks.com/topic/188664-loop-with-massive-bloated-code/ Share on other sites More sharing options...
oni-kun Posted January 16, 2010 Share Posted January 16, 2010 What exactly is bloated about that? Are you wanting to create a loop to compensate for each 'x = {$playerxarray}'? That won't exactly speed anything up, It may look more compact but it's iterating pointlessly and may lead you to problems in the end. Quote Link to comment https://forums.phpfreaks.com/topic/188664-loop-with-massive-bloated-code/#findComment-996008 Share on other sites More sharing options...
trq Posted January 16, 2010 Share Posted January 16, 2010 I would be more inclined to look at your database structure. field1, field2, field3, field4, field5 etc etc wreaks of poor design. Quote Link to comment https://forums.phpfreaks.com/topic/188664-loop-with-massive-bloated-code/#findComment-996017 Share on other sites More sharing options...
ignace Posted January 16, 2010 Share Posted January 16, 2010 I would be more inclined to look at your database structure. field1, field2, field3, field4, field5 etc etc wreaks of poor design. Post your database table structure DESCRIBE table1; DESCRIBE table2; .. Quote Link to comment https://forums.phpfreaks.com/topic/188664-loop-with-massive-bloated-code/#findComment-996034 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.