Q695 Posted February 12, 2009 Share Posted February 12, 2009 I have: <?php foreach( $_POST as $key => $value){ echo "<strong class='textb'>$key : $value <br /></strong>"; } ?> I need something that will dump the arrays submitted along with it. To see it run simply submit something within one of the forms (note: roof is complete). Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/ Share on other sites More sharing options...
premiso Posted February 12, 2009 Share Posted February 12, 2009 How many dimensions are you expecting to have? If a bunch you want to look into recursion, if not this would work: <?php foreach( $_POST as $key => $value){ if (is_array($value)) { foreach ($value as $k => $v) { echo " <strong class='textb'>$k : $v <br /></strong>"; } }else { echo "<strong class='textb'>$key : $value <br /></strong>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760259 Share on other sites More sharing options...
amites Posted February 12, 2009 Share Posted February 12, 2009 what about print_r($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760260 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 Thanks, those should help, since I was looking for something to datadump all post variables possible Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760289 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 They only seem to want to dump the first value in the array being submitted on the previous page Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760296 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 first version: <?php foreach( $_POST as $key => $value){ if (is_array($value)) { foreach ($value as $k => $v) { echo " <strong class='textb'>$k : $v <br /></strong>"; } }else { echo "<strong class='textb'>$key : $value <br /></strong>"; } } ?> <p></p> Seccond version: <?php foreach( $_POST as $key => $value){ echo "<strong class='textb'>$key :"; print_r($value); echo "<br /></strong>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760298 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 Anyone have ideas on how to dump the data from the form onto something else? Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760653 Share on other sites More sharing options...
rhodesa Posted February 12, 2009 Share Posted February 12, 2009 <?php function print_value ( $list ) { if(is_array($list)){ print "<ul>"; foreach($list as $k => $v){ print "<li><b>{$k}:</b> "; print_value($v); print "</li>"; } print "</ul>"; }else{ print $list; } } print_value($_POST); ?> Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760741 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 It is similar to how you populate with a shopping cart, but for some reason it doesn't output all the values that are checked . It just wants to give me the last value chosen on the list. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760754 Share on other sites More sharing options...
rhodesa Posted February 12, 2009 Share Posted February 12, 2009 are the names of the checkboxes all the same? like this: <input type="checkbox" name="foobar" value="check1" />Check 1 <input type="checkbox" name="foobar" value="check2" />Check 2 <input type="checkbox" name="foobar" value="check3" />Check 3 if so, that is your problem...it needs to be: <input type="checkbox" name="foobar[]" value="check1" />Check 1 <input type="checkbox" name="foobar[]" value="check2" />Check 2 <input type="checkbox" name="foobar[]" value="check3" />Check 3 Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760755 Share on other sites More sharing options...
Q695 Posted February 12, 2009 Author Share Posted February 12, 2009 That was the solution . Thank you very much rhodesa. Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760852 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Author Share Posted February 13, 2009 I guess I need a tiny bot more help. function print_value ( $list, $project ) { if(is_array($list)){ $project="$project <ul>"; foreach($list as $k => $v){ $project="$project <li><b>{$k}:</b> "; print_value($v, $project); $project= "$project </li>"; } $project= "$project </ul>"; }else{ $project= "$project $list"; } } print_value($_POST, $project); echo "project: $project"; Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-760963 Share on other sites More sharing options...
rhodesa Posted February 13, 2009 Share Posted February 13, 2009 I guess I need a tiny bot more help. function print_value ( $list, $project ) { if(is_array($list)){ $project="$project <ul>"; foreach($list as $k => $v){ $project="$project <li><b>{$k}:</b> "; print_value($v, $project); $project= "$project </li>"; } $project= "$project </ul>"; }else{ $project= "$project $list"; } } print_value($_POST, $project); echo "project: $project"; what are you trying to do? cus you keep rewriting the variable $project Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-761008 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Author Share Posted February 13, 2009 I need to load the project, then send it to a given e-mail address along with a message. Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-761044 Share on other sites More sharing options...
rhodesa Posted February 13, 2009 Share Posted February 13, 2009 are you trying to do this: <?php function make_list ( $list ) { if(is_array($list)){ $rval = "<ul>"; foreach($list as $k => $v){ $rval .= "<li><b>{$k}:</b> " . make_list($v) . "</li>"; } $rval .= "</ul>"; }else{ $rval .= $list; } return $rval; } $project = make_list($_POST); echo "project: $project"; ?> ?? Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-761081 Share on other sites More sharing options...
Q695 Posted February 13, 2009 Author Share Posted February 13, 2009 Yes, that was exactly what I was looking for . I was unsure why it was going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-761084 Share on other sites More sharing options...
Q695 Posted February 14, 2009 Author Share Posted February 14, 2009 I just realized that I needed to add another feature, since it's dumping project into itself for the required fields. Example: function make_list ( $list ) { if(is_array($list)){ $rval = "<ul>"; foreach($list as $k => $v){ if ($k!=project){ $rval .= "<li><b>{$k}:</b> " . mysql_real_escape_string(make_list($v)) . "</li>"; } } $rval .= "</ul>"; }else{ $rval .= "$list <br> $project"; } return $rval; } $project = make_list($_POST); echo "project: $project"; Quote Link to comment https://forums.phpfreaks.com/topic/144872-solved-array-datadump-in-random-variables/#findComment-762374 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.