1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Array help.

Discussion in 'PHP' started by debz89uk, Mar 22, 2010.

  1. #1
    I have a table that looks like this :

    [​IMG]

    created by the code :

    <?php
    $sql = mysql_query("SELECT * FROM ProgrammingFoundations");
    $i = 0;
    while($row = mysql_fetch_array($sql))
    {
    
    ?>
    <table align="center" border="1">
    <tr>
    
    
    <form method="POST" action="ProgrammingFoundationsAdd.php">
    <td width="100"><input type="text" name="data[<?php echo $i; ?>][student_id]" value=<?php echo $row['student_id'];?> size="10"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_1]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_2]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_3]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_4]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_5]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_6]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_7]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_8]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_9]" size="1"></td>
    <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_10]" size="1"></td>
    </tr>
    </table>
    <?php $i++; ?>
    PHP:
    When I fill out the form I get (using the print_r($_POST); ) something along the lines of :

    Array ( [data] => Array ( [0] => Array ( [student_id] => 200727669 [lecture_1] => on [lecture_2] => on [lecture_3] => on [lecture_4] => on [lecture_5] => on ) [1] => Array ( [student_id] => 200727668 [lecture_1] => on [lecture_2] => on [lecture_3] => on [lecture_4] => on [lecture_5] => on [lecture_6] => on [lecture_7] => on [lecture_8] => on [lecture_9] => on [lecture_10] => on ) [2] => Array ( [student_id] => 200712312 [lecture_2] => on [lecture_3] => on [lecture_4] => on [lecture_6] => on [lecture_7] => on ) [3] => Array ( [student_id] => 200755922 [lecture_1] => on [lecture_2] => on [lecture_3] => on [lecture_4] => on [lecture_8] => on ) [4] => Array ( [student_id] => 200812345 [lecture_3] => on [lecture_4] => on [lecture_5] => on [lecture_7] => on [lecture_8] => on [lecture_9] => on [lecture_10] => on ) [5] => Array ( [student_id] => 200828765 [lecture_1] => on [lecture_2] => on [lecture_3] => on [lecture_4] => on [lecture_5] => on [lecture_6] => on [lecture_7] => on [lecture_8] => on [lecture_9] => on ) [6] => Array ( [student_id] => 200812345 [lecture_3] => on [lecture_4] => on [lecture_5] => on [lecture_6] => on [lecture_7] => on [lecture_8] => on [lecture_9] => on [lecture_10] => on ) ) ) 
    Code (markup):
    (Depending on what boxes I tick of course).

    How do I go about putting this information into my database?
     
    Last edited: Mar 22, 2010
    debz89uk, Mar 22, 2010 IP
  2. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    variable will be like this
    $data = $_POST['data'];

    $data[0]['student_id']
    $data[0]['lecture_1']
    and more.

    you can using loop for $data[0] - $data[x]
     
    waterbomm, Mar 22, 2010 IP
  3. debz89uk

    debz89uk Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hmmmm can I put the variable $i in place of x in 'data[x]' because the thing is, I don't know how many entries I'm going to have, the fact that in my example the array data went to location(for search of a better word) "6" was just an example as the number varies depending on the user/uploaded file
     
    debz89uk, Mar 23, 2010 IP
  4. waterbomm

    waterbomm Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    for looping your data
    
    for($x=0, $y = count($_POST['data']); $x < $y; $x++)
    {
           $student_id = $data[$x]['student_id'];
           $lecture_1 = $data[$x]['lecture_1'];
           //-- and more
    }
    
    PHP:
     
    waterbomm, Mar 23, 2010 IP
  5. carfanatic01

    carfanatic01 Peon

    Messages:
    239
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Please continue on this guys because I am also observing the flow on this one.
    I am making my own study about this. Thank you so much.
     
    carfanatic01, Mar 23, 2010 IP