Jump to content


Photo

help with inserting an array into database


  • Please log in to reply
1 reply to this topic

#1 DataSpy

DataSpy
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 09 October 2006 - 05:24 AM

I'm using a for loop to create a specific number of containers, lets say 3, and each container has a different number.  I want to create an entry in the database for each contain but I've never done this before and has no idea about how to go about doing it.  Here some code in case it's hard to understand

<tr>
			<td>
			&nbsp;Company
		    </td>
			<td>
			&nbsp;<input type="text" name="company" size="18">
			</td>
		</tr>
		<tr>
			<td>
			&nbsp;Booking Number
		    </td>
			<td>
			&nbsp;<input type="text" name="booking_num" size="18">
			</td>
		</tr>
		<?php
		$number_of_containers=$HTTP_POST_VARS['number_of_containers'];
		for($i=0; $i < $number_of_containers; $i++){ 
		echo "
		<tr>
			<td>
			&nbsp;Container " .($i+1). "
			</td>
			<td>
			&nbsp;<input type='text' name='containers[$i]' value='Container #' size='18'>
			</td>
		</tr>";}
		?>
		<tr>

Then for each container # i want an entry in the database with the same company and booking#, but the container #'s will all be different.  I know how to enter stuff into a database, I just need help with this array. 

Any help greatly appretiated, thanx in advance!!!

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 October 2006 - 05:59 AM

I'm not sure I understand what you need help with... the PHP logic, or the actual DB statement.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users