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.

calling array

Discussion in 'PHP' started by roice, Dec 19, 2010.

  1. #1
    Hello,
    I have problem using array. hope you can help me -
    I print list of name with checkbox next to each name:

    $query = mysql_query("SELECT `name`,`id` FROM `list` ORDER BY id ASC");
    while($index = mysql_fetch_array($query)) 
    {
    	$id = $index['id'];
    	$name = stripslashes($index['name']);
    	echo "<div style='direction: ltr;'><input type='checkbox' id='check' name='name' value='$id' onclick='setChecks(this)' / > $name  </div>";
    
    }
    PHP:
    now I want to do 2 things:
    1. check if user pick exaclly 5 options
    2. Do update to the record, in the DB, for each of the five option that user picked.

    Thanks in advance.
     
    roice, Dec 19, 2010 IP
  2. mweldan

    mweldan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    this might give you an idea. for thing number 1.

    
    <form method="post" action="">
    test<input type="checkbox" name="name[]" value="1" />
    test<input type="checkbox" name="name[]" value="2" />
    test<input type="checkbox" name="name[]" value="3" />
    test<input type="checkbox" name="name[]" value="4" />
    test<input type="checkbox" name="name[]" value="5" />
    <input type="submit" />
    </form>
    
    
    <?php
    
    if ($_POST['name']){
        if ( count($_POST['name']) == 5){
            print "exactly 5 yo!\n";
        } else {
            print count($_POST['name']);
        }
    }
    
    
    ?>
    
    Code (markup):
     
    mweldan, Dec 19, 2010 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    OK, Thanks
    And how do I print each cell?
     
    roice, Dec 19, 2010 IP
  4. mweldan

    mweldan Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    loop.

    
        foreach($_POST['name'] as $lala){
            print $lala."<br />";
        }
    
    Code (markup):
     
    mweldan, Dec 19, 2010 IP
  5. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank You
    ....
     
    roice, Dec 19, 2010 IP