Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql: Inserting large groups of data as a range 1

Status
Not open for further replies.

treyhunsucker

Programmer
May 16, 2006
60
US
I am currently building a database for reports and records and would like to be able to add in large amounts of data by specifying a range.

Example:
I want to insert data into unit1, unit2, unit3....all the way to unit100.

I would like to be able to do something like:

=========================================================
$unit11=$_POST['unit1'];
$unit21=$_POST['unit2'];
$unit31=$_POST['unit3'];
....
$unit1001=$_POST['unit100'];

mysql_query("INSERT INTO provisioning (unit1-unit100) VALUES ('$unit11'-'$unit1001')
=========================================================

*just to make myself clear, I want to do a range like (unit1-unit100) instead of oing (unit1, unit2, unit3....)
 
You can omit the field names from your INSERT statement, and the data supplied will be inserted into the table's first-defined field onwards. For example:
[tt]
INSERT provisioning VALUES ('abc','def','ghi')
[/tt]
However, the actual values have to be specified individually.
 
$unit11=$_POST['unit1'];
$unit21=$_POST['unit2'];
$unit31=$_POST['unit3'];

mysql_query("INSERT INTO provisioning VALUES ('$unit11', '$unit21', '$unit31'))";

==========================================================

Thank you very much for your response, it will save me a LOT of typing lol. I would still like to know if there was a way to put in the VALUES as a range :)

 
You could assemble the query using program code - each iteration of a loop would append a value to the query string.
 
ty for your advice again, is there any chance you could give me some sample code or a link with a little more detail?
 
I don't use PHP, but in Perl it would be something like:
[tt]
$query='INSERT provisioning VALUES (';
for(1..100)
{
$query.="'".$_POST{"unit$_"}."',";
}
$query=substr($query,0,length($query)-1).')';
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top