/    Sign up×
Community /Pin to ProfileBookmark

I am creating a form dynamicly and i have no idea how many elements i am going to have

all i know the are all called

Q1
Q2
Q3
Q4
and so on

and i was wondering how i can create a dyamic call to all those variables

When i an creating the form i have

[code=php]
<form id=”quiz” name=”quiz” method=”post” action=”quiz.php”>
<?php
$i=0;
while ($i <= 10):
?>
<input type=”text” name=”Q<?php echo($i)?>” id=”=”Q<?php echo($i)?>”>

<?php
$i++;
endwhile;
?>
<input type=”submit” name=”Submit” value=”Submit” />
[/code]

Thanks for all the help

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottNov 18.2008 — You could actually give them all the same name:

&lt;input type="text" name="Q[]"&gt;

And then when you read the results at the server, [font=courier]$_GET['Q'][/font] will be an array holding each value.
Copy linkTweet thisAlerts:
@chickenlandNov 18.2008 — Or, you could loop through them...

[code=php]foreach($_POST as $k => $v){

if(stristr($k, 'Q')){

// $v is the value of the element
// $k the key

}

}[/code]
Copy linkTweet thisAlerts:
@moiseszaragozaauthorNov 18.2008 — Thanks

That helps alot
×

Success!

Help @moiseszaragoza spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...