Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong><code>Problem is that an insertion to a table with 90 fields seems hug[e]</code></strong></p> <p>your user table should be seperate from your games table and a third table for scores I think is how you are using this. That way none of the tables will ever have 90 columns. This will also allow a design that allows database growth</p> <p>What I think your current design is:</p> <pre><code>usser_id | g1r1 | g1r2 | g2r1 | g2r2 | g3r1 | g3r2 | ... | g50r1 | g50r2 </code></pre> <p>What your design should be like</p> <pre><code>Users: user_id | ..[user info]... Games: game_id | ...[game info]... Scores: score_id | game_id | user_id | score_1 | score_2 </code></pre> <p>And by all means also follow @bart2puck with his recommendation of writing html dynamically with php. This will make life so much easier. After changing database design, you will be able to insert the scores like:</p> <pre><code>$insert = "INSERT INTO Scores (user_id,game_id,homeScore,awayScore) VALUES "; foreach ($_POST['games'] as $key =&gt; $value){ $insert = "(".$_POST["user_id"].",".$key.",".$value[0].",".$value[1].")"; } //run query insert </code></pre> <p>That is if you name your input fields according to <code>name="games[game_id[]]"</code> where <code>game_id</code> is equivalent to your database <code>game_id</code> for instance for game 1 : <code>name="game[1[]]"</code> for both of the score fields for that game.</p> <p><strong>IMPORTANT!!</strong></p> <p>Please make sure that you either use query parameters or mysql escape your post input before running query! That way you will be protected from <a href="http://bobby-tables.com/" rel="nofollow">Bobby Tables</a> AKA SQL Injection</p> <p><strong>EDIT:</strong></p> <p>From the OP comment with table names you may want to use</p> <pre><code>$insert = "INSERT INTO Scores (user_id, game_id, homeScore, awayScore) VALUES "; foreach ($_POST["homeScore"] as $key =&gt; $value){ $insert = "(".$_POST["user_id"].",".$key.",".$value.",".$_POST["awayScore"][$key].")"; } //run query insert </code></pre> <p>Where you then name your form fileds <code>homeScore[game_id]</code> and <code>awayScore[game_id]</code> so the home score field of the game with a game id of 1 would be <code>name="homeScore[1]"</code></p> <p><strong>EDIT 2:</strong></p> <p>Here is also a better way to write your html using php with the correct form names if you follow my last edit.</p> <pre><code>for ($i = 1;$i&lt;=40;$i++){ echo "&lt;div class='form-right'&gt;&lt;input type='result' id='homeScore[$i]' name='awayScore[$i]' class='form-input' /&gt;&lt;/div&gt;\n"; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload