Jump to content

updating data from dynamic rows...


floorfiller

Recommended Posts

Hey guys,

 

I got another one that i could use some help on.  I have a input form that utilizes a javascript that adds additional rows to my table.  here is a look at what i got.

 

<script type="text/javascript">
function insertRow()
{
    var x = document.getElementById('results_table').insertRow(-1);
    var a = x.insertCell(0);
    var b = x.insertCell(1);
    var c = x.insertCell(2);
    var d = x.insertCell(3);
    var e = x.insertCell(4);

    a.innerHTML="<input type=\"text\" name=\"id\">";
    b.innerHTML="<input type=\"text\" name=\"place\">";
    c.innerHTML="<input type=\"text\" name=\"username\">";
    d.innerHTML="<input type=\"text\" name=\"earnings\">";
    e.innerHTML="<input type=\"button\" value=\"delete\" onClick=\"deleteRow(this)\">";
}

function deleteRow(r)
{
    var i=r.parentNode.parentNode.rowIndex;
    document.getElementById('results_table').deleteRow(i);
}

</script>

 

this is my code stored in the header of my page.  basically just a button to add a new row and a button in each row to delete rows if needed.

 

here is a look at my html table, pretty basic...

 

<table id="results_table">

            <th>Event ID</th><th>Place</th><th>Username</th><th>Earnings</th>

            <tr>
                <td><input type="text" name="id"></td><td><input type="text" name="place"></td><td><input type="text" name="username"></td><td><input type="text" name="earnings"></td><td><input type="button" value="delete" onClick="deleteRow(this)"</td>
            </tr>

        </table>

 

Now what I am hoping to acheive is once i submit all of these rows to the database i will insert each of these rows into their own row in the database.  is this doable?

 

the structure of my database is:

 

ResultID (Primary Key)

Place

Earnings

UserID (Foreign Key)

EventID (Foreign Key)

 

 

now i think the biggest problem i'm having with submitting data to the database is that in the original HTML form I am typing in the actual username and not the userID. 

 

so when it comes to processing I need to do a switch of these two things before I run my query.  Should something like this work?

 


$username = $_POST['username'];

$userID = "SELECT userID FROM users WHERE username="$username";

$query = mysql_query($userID);


 

also i've never tried to submit multiple entries at a time.  maybe i have to create an array somehow in order to capture each rows data.  any thoughts?

 

as always thanks for the help.

Link to comment
Share on other sites

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.