Jump to content

adding code to db using an array


runnerjp

Recommended Posts

Below is the full code to add races to my db.

 

<link rel="stylesheet" href="http://www.runningprofiles.com/dad/Form.Send/demo.css" type="text/css" />

<script type="text/javascript" src="http://www.runningprofiles.com/dad/mootools.js"></script>

<script type="text/javascript" src="http://www.runningprofiles.com/dad/Form.Send/demo.js"></script>



<script> 



function addRow() {   

          var tbl = document.getElementById('thetable');   

          var lastRow = tbl.rows.length;   

          var row = tbl.insertRow(lastRow);   

             

          var cell1 = row.insertCell(0);   

                  cell1.setAttribute('align','center') 

          var input = document.createElement('input');   

          input.name = 'date' + lastRow;   

          input.id = 'date' + lastRow;   

          cell1.appendChild(input);  



var cell2 = row.insertCell(1);   

                cell2.setAttribute('align','center') 

          input = document.createElement('input');   

          input.name = 'goals' + lastRow;   

          input.id = 'goals' + lastRow;   

          cell2.appendChild(input);  

             

          var cell3 = row.insertCell(1);   

                cell3.setAttribute('align','center') 

          input = document.createElement('input');   

          input.name = 'venue' + lastRow;   

          input.id = 'venue' + lastRow;   

          cell3.appendChild(input);   

  

var cell4 = row.insertCell(1);    

                cell4.setAttribute('align','center'); 

                 

                input = document.createElement('select');    

                input.name = 'terrain' + lastRow; 

                input.id = 'terrain' + lastRow; 

                 

                var s = "Road/Track/Multi Terrain/Cross Country".split("/"); 

                for(var i=0;i<s.length;i++) { 

                        var o = document.createElement("option"); 

                        o.value = s[i]; 

                        o.text = s[i]; 

                        input.add(o); 

                } 

         

                cell4.appendChild(input); 

        var cell5 = row.insertCell(1);    

                cell5.setAttribute('align','center'); 

                 

                input = document.createElement('select');    

                input.name = 'distance' + lastRow; 

                input.id = 'distance' + lastRow; 

                 

                var s = "3000m/5000m/10,000m/5 Miles/10 Miles/20 Miles/Half Marathon/Marathon /Other".split("/"); 

                for(var i=0;i<s.length;i++) { 

                        var o = document.createElement("option"); 

                        o.value = s[i]; 

                        o.text = s[i]; 

                        input.add(o); 

                } 

         

                cell5.appendChild(input); 

  

} 



    function delRow() {  

          var tbl = document.getElementById('thetable');   

          var lastRow = tbl.rows.length;   

          if (lastRow > 2) tbl.deleteRow(lastRow - 1);   

     } 





</script>

<br />

<center>

Here is a list of you up and coming races. Use the form below to add them so then <b>I</b> know which races you have gone for!



</center>

    <br />

<table width = "99%" class = 'forum'> 

                <tr> 

                    <td> 

                        <table width="100%" class = 'maintable'> 

                            <tr class = 'headline'> 

                            <td width = "12%" bgcolor="#003366"> 

                                    <div align = "center">Date</div></td> 



                                <td width = "14%" bgcolor="#003366"> 

                                   <div align = "center">Terrain</div></td> 



                                <td width = "12%" bgcolor="#003366"> 

                                     <div align = "center">Distance</div>                                   </td> 



                                <td width = "43%" bgcolor="#003366"> 

                                    <div align = "center">Venue

                                    </div></td> 



                                <td width = "19%" bgcolor="#003366"> 

                                    <div align = "center">Goals</div></td> 

                            </tr> 



                        <?php 

//$query="DELETE FROM dad WHERE id = '22' ";

//$result=mysql_query($query);



                                                 $getthreads = 

                                "Select * from races ORDER BY date ASC"; 



                            $getthreads2=mysql_query($getthreads) or die("Could not get threads"); 



                            while ($getthreads3=mysql_fetch_array($getthreads2)) 

                                { 

                                 

                      

                                ?><tr <? if ( $getthreads3['date'] == date("d/m/Y") ) { echo 'bgcolor="#CAD9D9"'; }?> > 

<td width="10%" height="39" align="center" valign="middle"><?php 

                            echo $getthreads3['date'];?> 



                                </td>  

<td width="15%" align="center" valign="middle"> <?php echo $getthreads3['distance']; ?>  

                                </td>   

<td width="15%" align="center" valign="middle"><?php echo $getthreads3['terrain']; ?>  

                       </td><td align = "center" valign = "middle"><?php echo $getthreads3['venue']?> </td> 



                                <td align="center" valign = "middle"> 

<?php echo $getthreads3['goals']?>



</td> 



                       

                                    </tr> 

                            <?php      } 

                        ?> 

                  </table></td> 

                </tr> 

</table>

    



<form id="myForm" action="Form.Send/ajax.form.php" method="post">

    

     <table align="center" style="WIDTH: 100%;BACKGROUND: #C0C0C0; BORDER-COLLAPSE: collapse" id="thetable"> 

   <tbody> 

     <tr> 

       <td> 

         <p align="center">Date</p></td> 

       <td> 

         <p align="center">Distance</p></td> 

       <td> 

         <p align="center">Terrain</p></td>

<td> 

         <p align="center">place</p></td>  

       <td> 

         <p align="center">Goals</p></td> 

    </tr> 

     <tr> 

       <td align="center"> 

        <input  name="date" value="<?php echo date("d/m/Y");?> " /></td> 

       <td align="center">

        <select name="distance">

<option value="3000m">3000m</option>

<option value="5000m">5000m</option>

<option value="10,000m">10,000m</option>

<option value="5 Miles">5 Miles</option>

<option value="10 Miles">10 Miles</option>

<option value="20 Miles">20 Miles</option>

<option value="Half Marathon">Half Marathon</option>

<option value="Marathon">Marathon</option>

<option value="Other">Other</option>

</select>

         </td> 

       <td align="center"> 

       <select name="terrain">

<option value="Road">Road</option>

<option value="Track">Track</option>

<option value="Multi Terrain">Multi Terrain</option>

<option value="Cross Country">Cross Country</option>

</select>

</td> 

       <td align="center"> 

        <input  name="venue" /></td> 

<td align="center"> 

        <input  name="goals" /></td> 

    </tr> 

  </tbody> 

</table> 

<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse"> 

     <tr> 

       <td> 

       <p align="center"> 

          <input type="button" value="Add Anouther" onclick="addRow()" /> 

          <input type="button" value="Subtract Row" onclick="delRow()" /> 

                </p> 

       </td> 

    </tr> 

</table> 



<center>



		<input type="submit" name="button" id="submitter" /></center>

	<span class="clr"><!-- spanner --></span>

	</div>

        

        

        

</form>

    

    <center>

    

    

<div id="log">

	<center><h3>Ajax Response</h3>

	<div id="log_res"><!-- spanner --></center></div>

</div>

</center>

<span class="clr"><!-- spanner --></span>

 

 

As you can see there is an option to add a number of rows so you can add more than 1 race... what would i need to do to add all races the user inputs?? a loop of some kind?

Link to comment
Share on other sites

ver dump gets me

 

Array

(

    [date] => 14/03/2010

    [venue] => 1

    [goals] => 1

    [date2] => 14/03/2010

    [venue2] => 2

    [goals2] => 2

    [date3] => 14/03/2010

    [venue3] => 3

    [goals3] => 3

    [distance] => 5000m

    [terrain] => Road

    [distance2] => 3000m

    [terrain2] => Track

    [distance3] => 10,000m

    [terrain3] => Cross Country

)

 

if that helps at all

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.