Jump to content

Arrays with XML


frozenlight777

Recommended Posts

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
Share on other sites

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
Share on other sites

$_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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.