TOMMURRAY Posted May 8, 2007 Share Posted May 8, 2007 Hi All I have a piece of code in the form of an array, I am wanting to insert this information into a MySQL database into one row. At this present time I wish to insert only the score field. The database has a column for each of the Hole's (1 to 18), the value is that of the score input. Can anyone point me in the right direction? Thank you in advance Tom for ($i = 1; $i < 19; $i++) { echo "<tr>\n"; echo "<td>Hole #{$i}</td>\n"; echo "<td><input type=\"text\" size=\"4\" name=\"score[]\" /></td>"; echo "<td><input type=\"text\" size=\"4\" name=\"si[]\" /></td>"; echo "<td><input type=\"text\" size=\"4\" name=\"par[]\" /></td>"; echo "</tr>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/50477-php-array-insert-into-mysql-database/ Share on other sites More sharing options...
Thierry Posted May 8, 2007 Share Posted May 8, 2007 Might be easier to just use a single field for all the holes, and put the data there as a single string. For instance, in hole 1 you have a score of 3, then 8 for hole 2 and 5 for hole 3, it would be put in the database as 3,8,5 and you could use the explode() function to make it an array again. Right now, you'd simply have to do it like this: $scores = $_POST["score"]; $hole_1_score = $scores[0]; $hole_2_score = $scores[1]; $hole_3_score = $scores[2]; //etc... The same would apply for your query, having to write down each separate field name. Quote Link to comment https://forums.phpfreaks.com/topic/50477-php-array-insert-into-mysql-database/#findComment-248003 Share on other sites More sharing options...
TOMMURRAY Posted May 8, 2007 Author Share Posted May 8, 2007 Hi thank you for your reply, sorry if I sound thick are you implying that all i need to do is along the lines of this? insert into "table" (hole_1, hole_2, hole_3) Values ($hole_1_score, $hole_2_score, $hole_3_score ) I'm new to arrays, so I dont have any real understanding of them. Thank you for your help. Tom Quote Link to comment https://forums.phpfreaks.com/topic/50477-php-array-insert-into-mysql-database/#findComment-248025 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.