cliftonbazaar Posted March 12, 2018 Share Posted March 12, 2018 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 12, 2018 Share Posted March 12, 2018 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. 1 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 12, 2018 Share Posted March 12, 2018 PS - besides what Barand has said... You really should think about using POST forms for retrieving this much input from the user. Is there some reason that your example is using all GET elements? Quote Link to comment Share on other sites More sharing options...
gizmola Posted March 12, 2018 Share Posted March 12, 2018 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. Quote Link to comment 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.