frozenlight777 Posted May 28, 2008 Share Posted May 28, 2008 I'm looping through an array with an xml file and it displays great...... <form method="POST" action="uploadlist.php"> <table align="center" border="1" width="600"> <tr> <th>Asset Tag</th> <th>Type</th> <th>Service Tag</th> <th>User</th> </tr> <?php foreach( $data as $row ) { ?> <tr> <td><input name="Asset_Tag" value = "<?php echo( $row['Asset_Tag']); ?> "/></td> <td><input name="Type" value = "<?php echo( $row['Type']); ?> "/></td> <td><input type="hidden" name="Service_Tag" value = "<?php echo( $row['Service_Tag']); ?>"/></td> <td><input name="User" value = "<?php echo($row['User']); ?> "/></td> <td><input type="hidden" name="_submit_check" value="1"/> </td> </tr> <?php } ?> <td><input type="submit" value="Send to Database"/></td> </table> </form> however, how can I display the same results in the uploadlist.php file... I can't seem to get the array to display with the POST variables..... and I have no idea what other way there is..... ideas? Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/ Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 add [] to all of your input names...and if service tag is the unique id for each item, use this: <?php foreach( $data as $row ) { ?> <tr> <td><input type="text" name="Asset_Tag[<?php echo $row['Service_Tag']; ?>]" value="<?php echo $row['Asset_Tag']; ?>"/></td> <td><input type="text" name="Type[<?php echo $row['Service_Tag']; ?>]" value="<?php echo $row['Type']; ?>"/></td> <td><input type="text" name="User[<?php echo $row['Service_Tag']; ?>]" value="<?php echo $row['User']; ?>"/></td> <td><input type="hidden" name="_submit_check" value="1"/> </td> </tr> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551923 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 interesting.... now how would i display that on the other page...something like $_POST("Asset_Tag"); ? Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551933 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 $_POST would now look something like this: Array ( 'Asset_Tag' => Array ( 'svc_tag_1' => 'Asset Tag for Service Tag 1', 'svc_tag_2' => 'Asset Tag for Service Tag 2', 'svc_tag_3' => 'Asset Tag for Service Tag 3', 'svc_tag_4' => 'Asset Tag for Service Tag 4' ), 'Type' => Array ( 'svc_tag_1' => 'Type for Service Tag 1', 'svc_tag_2' => 'Type for Service Tag 2', 'svc_tag_3' => 'Type for Service Tag 3', 'svc_tag_4' => 'Type for Service Tag 4' ), 'User' => Array ( 'svc_tag_1' => 'User for Service Tag 1', 'svc_tag_2' => 'User for Service Tag 2', 'svc_tag_3' => 'User for Service Tag 3', 'svc_tag_4' => 'User for Service Tag 4' ) ) to loop over the info: <?php foreach($_POST['Asset_Tag'] as $Service_Tag => $Asset_Tag){ $Type = $_POST['Type'][$Service_Tag]; $User = $_POST['User'][$Service_Tag]; print $Asset_Tag.' : '.$Type.' : '.$User; } ?> Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551941 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 i'm sorry to be a pain but each array is independent from eachother. What you posted seemed to work but it only displayed in the URL. Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551949 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 put a print_r($_POST); on the page it submits to, and post what that outputs please Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551956 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 all it displays is: Array() with all the content in the URL Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551959 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 then something is wrong on your HTML page. can you do a view source on the page that display all the input boxes, and copy paste that? please use code tags if you do..it's the button with the # on it in the toolbar Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551963 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 upload.php <?php error_reporting(E_ALL); require_once( "include.php" ); XMLParse(); ?> <html> <form method="REQUEST" action="uploadlist.php"> <table align="center" border="1" width="600"> <tr> <th>Asset Tag</th> <th>Type</th> <th>Service Tag</th> <th>User</th> </tr> <?php foreach( $data as $row ) { ?> <tr> <td><input type="text" name="Asset_Tag[<?php echo $row['Asset_Tag']; ?>]" value="<?php echo $row['Asset_Tag']; ?>"/></td> <td><input type="text" name="Type[<?php echo $row['Type']; ?>]" value="<?php echo $row['Type']; ?>"/></td> <td><input type="text" name="Service_Tag[<?php echo $row['Service_Tag']; ?>]" value="<?php echo $row['Service_Tag']; ?>"/></td> <td><input type="text" name="User[<?php echo $row['User']; ?>]" value="<?php echo $row['User']; ?>"/></td> </tr> <?php } ?> <td><input type="submit" value="Send to Database"/></td> </table> </form> </html> and then the uploadlist.php file... which isn't anything yet except for <?php print_r($_POST); ?> Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551967 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 wow I apologize.... i used request instead of post.... been a long day... it displayed the whole array now... Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551968 Share on other sites More sharing options...
rhodesa Posted May 28, 2008 Share Posted May 28, 2008 i was gonna say...originally you had it POST... Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551970 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 Great... thanks for you help i got the array working so now how would i go about looping the data like i did in the first table.. something like <?php foreach(????????] as ????){ echo "<td>$_POST['Asset_Tag']</td>"; echo "<td>$_POST['Type']</td>"; echo "<td>$_POST['Service_Tag']</td>"; echo "<td>$_POST['User']</td>"; } ?> not sure what the looping variables would be... Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551977 Share on other sites More sharing options...
frozenlight777 Posted May 28, 2008 Author Share Posted May 28, 2008 nevermind i got it. foreach($_POST['Asset_Tag'] as $key => $value){ $Asset_Tag = $_POST['Asset_Tag'][$value]; print $Asset_Tag; echo "<br/>"; } thanks for you're help tho. you certainly got this working for me. Link to comment https://forums.phpfreaks.com/topic/107667-arrays-with-xml/#findComment-551983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.