Jump to content

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
https://forums.phpfreaks.com/topic/306807-putting-lots-of-values-into-a-database/
Share on other sites

That is a spreadsheet, not a database table design. When you start labelling columns with names ending in 1,2,...,N then you have got the design wrong.

 

Normalize your table design then come back.

  • Like 1

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