Dynamically name array <input> checkbox ? - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-27-2009, 04:10 AM   #1 (permalink)
Junior Member
 
Join Date: Jan 2009
Posts: 1
Default Dynamically name array <input> checkbox ?

Dynamically name array <input> checkbox ?

Is it possible to generate dynamic array names for input checkbox forms ?

I'm using this code to generate a form of text fields and checkboxs

PHP Code:
<?php 
  
require_once("includes/connection.php"); 
  require_once(
"includes/functions.php"); 
  include(
"includes/header.php"); 
?> 
<?php 
    $query 
"SELECT key_id, words FROM keywords"
    
$result mysql_query($query); 
    
confirm_query($result); 
    
$options ""
    while(
$row mysql_fetch_array($result)){ 
        
$options .= "{$row[1]}:<input type=\"checkbox\" value=".$row[0]." name=\"section[]\" />\n"
    } 
    
$number_of_uploads 3
?> 
<body> 
    <div id="con"> 
        <form name="upload_form" action="upload.php" method="post" enctype="multipart/form-data"> 
        <?php 
            
for($counter 1;$counter<=$number_of_uploads;$counter++){ 
        
?> 
        <p> 
        <b>Image:</b> 
            <textarea name="title[]" cols="30" rows="1"></textarea> 
        </p> 
        <p> 
        <b>Sections:</b> 
        <?php echo $options ;?> 
        </p> 
        <?php 
            

        
?> 
        <br/> 
        <p> 
            <input type="submit" name="submit" value="Add Photos" /> 
        </p> 
        </form> 
    </div> 
</body> 
</html>
The while loop generates the checkbox's and the values from all the checkbox's are stored in section[] which can them be used from $_POST['section'].

PHP Code:
while($row mysql_fetch_array($result)){ 
    
$options .= "{$row[1]}:<input type=\"checkbox\" value=".$row[0]." name=\"section[]\" />\n"

What I want to be able to do is create a seperate array for each loop of the while loop so each set of checkbox's created in one loop has it's own array.

Something like:

PHP Code:
name="section[].$row[0]\" 
How can I have a seperate array for each loop of the array?

How can I then access this array with php from the $_POST array ?

I thought I might be able to access the array with something like:
But this doesn't work.

PHP Code:
<?php
    
echo "<pre>";
        
print_r($_POST['section'['.1.']]);
    echo 
"</pre>";
?>
ttmt is offline   Reply With Quote
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:34 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting