fohanlon Posted March 9, 2006 Share Posted March 9, 2006 Hi Does any one have any ideas how to create varaibles from a for loop that will be accessible on this page and can be posted to other pagesHeres what I havefor($i = 0; $i < 6; $i++){ $g = "gender".$i; $d = "day".$i; $m = "month".$i; $y = "year".$i; $e= "education".$i; $gender."$i" = $_POST[$g]; $day."$i" = $_POST[$d]; $month."$i" = $_POST[$m]; $year."$i" = $_POST[$y]; $today = date("Y-m-d"); $t = explode("-", $today); $person_age = calculate_age($day, $month, $year); $education = $_POST[$e]; echo "Gender: " . $gender."$i" . " Day: " . $day."$i" . " Month: " . $month."$i" . " Year: " . $year."$i" . " Education: " . $education."$i" . '<br>';}I want to be able to create 6 sets of varaibles for gender, age, month, year, education and be able to access them on the page as separate variables.many thanks,Fergal. Quote Link to comment Share on other sites More sharing options...
littlened Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353234:date=Mar 9 2006, 01:37 PM:name=fohanlon)--][div class=\'quotetop\']QUOTE(fohanlon @ Mar 9 2006, 01:37 PM) [snapback]353234[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi Does any one have any ideas how to create varaibles from a for loop that will be accessible on this page and can be posted to other pagesHeres what I havefor($i = 0; $i < 6; $i++){ $g = "gender".$i; $d = "day".$i; $m = "month".$i; $y = "year".$i; $e= "education".$i; $gender."$i" = $_POST[$g]; $day."$i" = $_POST[$d]; $month."$i" = $_POST[$m]; $year."$i" = $_POST[$y]; $today = date("Y-m-d"); $t = explode("-", $today); $person_age = calculate_age($day, $month, $year); $education = $_POST[$e]; echo "Gender: " . $gender."$i" . " Day: " . $day."$i" . " Month: " . $month."$i" . " Year: " . $year."$i" . " Education: " . $education."$i" . '<br>';}I want to be able to create 6 sets of varaibles for gender, age, month, year, education and be able to access them on the page as separate variables.many thanks,Fergal.[/quote]I don't understand what you want, but maybe using an array would help? for example $year[$i], $day[$i]. Quote Link to comment Share on other sites More sharing options...
fohanlon Posted March 9, 2006 Author Share Posted March 9, 2006 Never thought of an array I will try this thanks Quote Link to comment Share on other sites More sharing options...
sasa Posted March 9, 2006 Share Posted March 9, 2006 [!--quoteo(post=353234:date=Mar 9 2006, 02:37 PM:name=fohanlon)--][div class=\'quotetop\']QUOTE(fohanlon @ Mar 9 2006, 02:37 PM) [snapback]353234[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi Does any one have any ideas how to create varaibles from a for loop that will be accessible on this page and can be posted to other pagesHeres what I havefor($i = 0; $i < 6; $i++){ $g = "gender".$i; $d = "day".$i; $m = "month".$i; $y = "year".$i; $e= "education".$i; $gender."$i" = $_POST[$g]; $day."$i" = $_POST[$d]; $month."$i" = $_POST[$m]; $year."$i" = $_POST[$y]; $today = date("Y-m-d"); $t = explode("-", $today); $person_age = calculate_age($day, $month, $year); $education = $_POST[$e]; echo "Gender: " . $gender."$i" . " Day: " . $day."$i" . " Month: " . $month."$i" . " Year: " . $year."$i" . " Education: " . $education."$i" . '<br>';}I want to be able to create 6 sets of varaibles for gender, age, month, year, education and be able to access them on the page as separate variables.many thanks,Fergal.[/quote]look this[code]<?php$test1="one";$a="test";$b=1;$c=2;$d=3;${$a.$c}="two"; //$test2='two'${"test".$d}="ten"; //$test3='ten'$e="test4";$test4="xyz";echo ${$a.$b}."</ br>\n";echo ${"test".$c}."</ br>\n";echo ${$a.$d}."</ br>\n";echo $$e."</ br>\n";$$e="abc"; // $test4='abc'echo $test4;?>[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 9, 2006 Share Posted March 9, 2006 you may also just want to check into the extract() function. it will pull all the contents of your $_POST variable into their own variables. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.