Jump to content

Recommended Posts

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";
}

Link to comment
https://forums.phpfreaks.com/topic/50477-php-array-insert-into-mysql-database/
Share on other sites

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.

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

 

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.