Jump to content

loop with massive bloated code


cliftonbazaar

Recommended Posts

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  :D

 

	  //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

 

Link to comment
https://forums.phpfreaks.com/topic/188664-loop-with-massive-bloated-code/
Share on other sites

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.

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.