Jump to content

Putting lots of values into a database


cliftonbazaar

Recommended Posts

Currently my code is

$sql_statement="UPDATE players
		SET cls = '".$_GET['cls']."',
			rjt = '".$_GET['rjt']."',
			thrawn = '".$_GET['thrawn']."',
			rolo = '".$_GET['rolo']."',
			ipd = '".$_GET['ipd']."',
			arena1 = '".$_GET['arena1']."', arena2 = '".$_GET['arena2']."', arena3 = '".$_GET['arena3']."', arena4 = '".$_GET['arena4']."', arena5 = '".$_GET['arena5']."',
			fleet1 = '".$_GET['fleet1']."', fleet2 = '".$_GET['fleet2']."', fleet3 = '".$_GET['fleet3']."', fleet4 = '".$_GET['fleet4']."', fleet5 = '".$_GET['fleet5']."'
		WHERE ally_code = '".$_SESSION['ally_code']."'";

Each GET is the same as the column in my database; is there a loop to make this smaller in code?  The reason I ask this is because it's going to get bigger and bigger.

While I realise that this isn't the best way to update the database it works for my needs.

James

Link to comment
Share on other sites

Barand pretty much said it. What you have there is a repeating group on arena and fleet at minimum. You will forever be changing your database and php code, not to mention the horror of queries

 

$sql = "... WHERE fleet1 = 'foo' OR fleet2 = 'foo' OR fleet3 = 'foo' etc.";
You add column fleet{n} and now you have to go change all your queries. It's relationally incorrect, but also horrible to work with, and will require continual updating and retesting of existing working code.
Link to comment
Share on other sites

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.