I using jquery to add / remove inputs
i use append to add multiple Tr for Date / revenue
also i use another append to add multiple td for revenue in same Tr of date
i Add multiple date inputs and into this table i add multiple revenue inputs
I have to use name="date[]" to can use for loop and insert each one in mysql table
but in sametime there is multiple name="revenue[]"
Here is example
<form method="post" action ="">
<table>
<tr>
<td>Date : <input type="text" name="date[]" value="25/07/2013"></td>
<td>Revenue : <input type="text" name="revenue[]" value="1"><br>
Revenue : <input type="text" name="revenue[]" value="2" ><br>
</td>
</tr>
<tr>
<td>Date : <input type="text" name="date[]" value="26/07/2013"> </td>
<td>
Revenue : <input type="text" name="revenue[]" value="12"><br>
Revenue : <input type="text" name="revenue[]" value="13"><br>
Revenue : <input type="text" name="revenue[]" value="14"><br>
</td>
</tr>
<tr>
<td>Date : <input type="text" name="date[]" value="27/07/2013"></td>
<td>
Revenue : <input type="text" name="revenue[]" value="30"><br>
</td>
</tr>
</table>
<br><br><input name="submit" value="submit" type="submit">
</form>
PHP code
<?php
if(isset($_POST['submit'])){
$date = $_POST['date'];
echo "Results<br>";
for($i = 0; $i<count($date); $i++){
echo "Date : $date[$i] <br>";
print_r($_POST['revenue']);
echo "<br><br>";
}
}
?>
Results is :
Date : 25/07/2013
Array ( [0] => 1 [1] => 2 [2] => 12 [3] => 13 [4] => 14 [5] => 30 )
Date : 26/07/2013
Array ( [0] => 1 [1] => 2 [2] => 12 [3] => 13 [4] => 14 [5] => 30 )
Date : 27/07/2013
Array ( [0] => 1 [1] => 2 [2] => 12 [3] => 13 [4] => 14 [5] => 30 )
I wanted results to be like that
Date : 25/07/2013
Array ( [0] => 1 [1] => 2)
Date : 26/07/2013
Array ( [0] => 12 [1] => 13 [1] => 14)
Date : 27/07/2013
Array ( [0] => 30 )
i want to insert each date into a table with the multiple revenue in same row
Like In Row
Date : 25/07/2013 Revenue : 1-2
Date : 26/07/2013 Revenue : 12-13,14
Date : 27/07/2013 Revenue : 30
Its very important for me, Thank You Very Much