RE: [PHP] loop variable
| From: | Niklas Lampén | Date: | Wed, 07 Nov 2001 08:32:55 +0000 |
| Subject: | RE: [PHP] loop variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-73693@lists.php.net to get a copy of this message | ||
Uups... Stupid me. Like this ofcourse:
<?
for ($i = 0; $i < count($artists); ++$i) {
$output .= "<i>$artist[$i]</i><br>";
};
print $output;
?>
Niklas
-----Original Message-----
From: Niklas Lampén [mailto:niklas.lists@publico.fi]
Sent: 7. marraskuuta 2001 10:30
To: 'Michael P. Carel'; Php-General
Subject: RE: [PHP] loop variable
If you want to use that <i>Artist</i> formated output in several places,
do it like this:
<?
for ($i = 0; $i < count($artists); ++$i) {
$output .= "<i>$artist[$count]</i><br>";
};
print $output;
?>
Niklas
-----Original Message-----
From: Michael P. Carel [mailto:mikecarel@team5.teamglac.com]
Sent: 7. marraskuuta 2001 9:44
To: php-general@lists.php.net
Subject: [PHP] loop variable
Hi there,
I have a problem regarding the "for" loop or other types of loop. Im
using the "for" loop statement to read and declare a variable for an
array of elements, but my problem is when i used the declared variable
outside the loop statement it does not give me the correct output.
Here's my
sample:
<html>
<head>
</head>
<body>
<?
// check for $submit
if (!$submit)
{
// and display form
?>
<form action="test2.php" method="GET">
<input type="checkbox" name="artist[]" value="Bon Jovi">Bon Jovi
<input
type="checkbox" name="artist[]" value="N'Sync">N'Sync
<input
type="checkbox" name="artist[]" value="Boyzone">Boyzone <input
type="checkbox" name="artist[]" value="Britney Spears">Britney
Spears
<input type="checkbox" name="artist[]" value="Jethro
Tull">Jethro Tull
<input type="checkbox" name="artist[]" value="Crosby, Stills &
Nash">Crosby, Stills & Nash <br> <input type="submit"
name="submit"
value="Select"> </form> <? } // or display the selected artists else {
?> <b>And here are your selections:</b> <br> <? // use a "for"
loop to
read and display array elements for($count = 0; $count <
sizeof($artist); $count++) { echo "<i>$artist[$count]</i><br>";
$test=$artist[$count]; print("$test"); /*this line gives the proper
output */ } /*print("$test"); when i used this line and comment the
previous print line, it does not give me a proper out*/
}
?>
</body>
</html>
I want to used the for loop output all thru out my program.and not just
within the loop. Please help.
Regards,
Michael P. Carel
Systems Administrator
TEAM PACIFIC CORPORATION
FTI Taguig Metro, Manila. PHIL.
Tel. Nos. (02) 838-50-05 local 363
(02) 838-84-38 direct
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net