I need to insert information into for example "sample_table" as below it will be from Cat_ID 0 - 6388, how can I achieve this with out having to write lines 0-6388 ? INSERT INTO `sample_table` (`Cat_ID`, `Lang`, `Zone1`, `Zone2`, `Zone3`, `Zone4`, `Zone5`, `Zone6`, `Zone7`, `Zone8`, `Zone9`, `Zone10`, `Zone11`, `Zone12`, `Zone13`, `Zone14`, `Zone15`, `Zone16`, `Zone17`, `Zone18`, `Zone19`, `Zone20`) VALUES (0, 'English', 'some info', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''), (6388, 'English', 'some info', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); Code (markup):
Insert into is to create new rows. Are you creating new rows or putting data into exotsing rows? If you are inserting new rows you can use a loop (either in SQL or in the page code). The syntax will vary depending on the DB you are using. Here is some psuedo code to demonstrate the principle: For i = 0 to 6388 Insert Into table (cat_id, lang,...) Values (i, 'data',...) Next Of course, that only works if everything except the ID field is going to have the same data. Another method would be if you have the data in say a spreadsheet you can do an import. Also, if the Cat_ID is the unique identifier, it would be better form to not add its value through an insert, rather it would be better to set that filed to a self incrementing value. If you are adding data to existing rows, then you could do: Update table Set Lang = 'data' Where Cat_ID < 6389 For more informative help: What DB and version are you using? Other than the ID will the data you want to add via this method be the same? Do you have this data already in a CSV or spreadsheet? Are you doing this through the database directly or through a php/asp page?
Thanks for the reply @bluegrass_special I'm creating new rows into an empty table, all but the Cat_ID starting at 0-6388 will be the same, (0-6388, 'English', 'same', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); I'm running (Windows Essentials (x86)) mysql 4.1.22. Preferable I would like to insert this information through SQL phpmyadmin or I'm open to suggestions for php 5. <?php For i = 0-6388; // which is wrong I know, so whats the correct way mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database name") or die(mysql_error()); mysql_query("INSERT INTO sample_table (Cat_ID, Lang, Zone1) VALUES([B]What would go here, i ? [/B], 'English', 'data', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); ") or die(mysql_error()); echo "Data Inserted!"; ?> Code (markup):
I guess it would be something like this: <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database name") or die(mysql_error()); for($count=0; $count<=6388; $count++){ mysql_query("INSERT INTO sample_table (Cat_ID, Lang, Zone1,...put other columns here...) VALUES($count, 'English', 'data', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); ") or die(mysql_error()); } echo "Data Inserted!"; ?> PHP: But if the Cat_ID is just an ID then you would probably want to have auto increment/identity on that coulmn, and leave out the Cat_ID column in the insert. If you already have the data in some spreadsheet or csv file, then you should check out phpMyAdmin import functions.
Thanks very much @kjewat however i'm getting the following error Parse error: syntax error, unexpected T_CLASS, expecting T_STRING or T_VARIABLE or '$' in EDITED line 7 PHP: 7 been VALUES('$count, 'English', etc... Which I assume is something eles rather then the code ?
Got that solved a small error in the code above, no harm done, it was my fault. @kjewat thanks a million