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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.