Multiple Table Insert From Tab Delimited File
I have a page I'm coding for batch updates from a tab delimited file. Each row has data that has to be checked against and inserted/updated on different tables in my mySQL database.
How would I go about parsing through the tab delimited file and then storing data between the tabs in order to insert individually into separate tables??
Here's what I have so far...
$contents = file('/myfile.txt');
for ($i=0; $i<sizeof($contents); $i++) {
$line = trim($contents[$i]); $arr = explode(" ", $line);
$line[$i] = array('ID' => $arr[0], 'Record_Type' => $arr[1], 'First_Name' => $arr[2], 'MI' => $arr[3], 'Last_Name' => $arr[4], 'Firm' => $arr[5], 'Address' => $arr[6], 'type' => rtrim($arr[13]));
I need to take the different columns.. ID, Record_Type, etc. and update different tables with each value where the IDs match.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Tab Delimited Txt File To Php Html Table
Wouldn't you know that when I finally find a tutorial using Google that does exactly what I want, the code doesn't run when I use it ... However, when it gets to this line, for ($i=0; $i<td>$line[0]</td>, it chokes on one of the '>'. Since my php skills are very basic, and in no way include arrays, can someone assist me with this? If it's easier to do it differently, what I'd like to do is create a table in Excel/Access, export it to the server (to a tab-delimted text file, since I'll be using commas in my table cells), and have it display in an HTML table. If I can't figure this out, I'm tempted to just export to HTML from one or the other program (not sure quite yet which I would use), so ...
Importing A Flat Pipe Delimited File Into A MySQL Data Table
I have done this in perl but eeew I don't want to use perl anymore. I want to be able to take a flat file that looks like this: mbriones@...|Marian|Briones bobsmith@...|Bob|Smith janedoe@...|Jane|Doe (etc) The table has more than 3 fields, so I'd want to process the flat file and then do an INSERT into mailinglist SET field=$value for each line. Does someone have a nice way for me to do this? The flat file will be uploaded to the server via a form (copy) and then be processed.
Multiple Table Insert
I have a table that when you add a new department it will add the name to the table and assign the row and id based on an auto_increment column. From there you need to get the value of the last insert id. SO what I did was use the msql_insert_is() function. and assigned it to a variable. I then used that variable in my next query because this vaule is a forigen key in another table. Here is my code it should be exectued if you where to post this page with the value of $department_id = "" then the section of script in question will execture. Essentially need it to grab this id number and then place it into 2 more insert statements that should execute immediately after the first insert statement. Then only insert id that I would need is the one produced in the first insert statement what an auto increment value is assigned to the same table as the department_name Code:
Multiple Table Insert With Php Mysql
I am having and issue getting this code working. It seems rather simple but I cannot figure out why only one sql statement is exectuing and the insert statements the other 2 are not exectuting and updating the other 2 tables. I need to do this. I need to update one table, then from that I need to retrieve the mysql_insert_id or just get the id of the last record in the tabe. There is an auto increment column that gets assigned a unique id each time a record is inserted. I need this id number then I need it to place data into 2 other tables that will use this value as a reference. here is the code:
Insert Multiple File Paths Into Db?
I am able to upload multiple files but i would like to store the file paths from the array i declared into the database (mysql). I'm not sure whether my query is correct but here it is. It turned up funny in the database when I checked. just ".","/","l" respectively in each picPath. the full file path was not inserted. I used a for loop for the multiple file upload. $sql="INSERT INTO picturesimage (picPath1, picPath2, picPath3) VALUES ('$uploadfile[0]','$uploadfile[1]','$uploadfile[2]')"; $result = executes($sql);
Comma Delimited File
I am trying to read comma delimited rows of text. The problem is that some fields may be encapsulated in "" - particularly the text fields but not numeric fields. Is there a simple efficient way to parse the fields with comma but also strip off the "" encapsulating some of the fields with php? The problem is the "" encapsulation is optional. Some fields will have it, some won't.
Delimiting A Non-delimited File
I have a text file, with addresses of business' that I would like to convert to a more useable format ie CSV. Currently there is no delimiting of the various address components. "A 1 AUTO SALES 1224 S BROADWAY ST WICHITA, KS 67211-3124 316-263-8748" "ABERLE FORD INC 1025 MAIN ST SABETHA, KS 66534-1893 913-284-3122" "ACTION AUTO RENTAL & SALES 1101 W 4TH AVE HUTCHINSON, KS 67501 316-662-3699" As you can see from the examples above the only consistent items are the state and the phone number, and the city is always followed by a comma. I am new to regex and the whole range of string handling functions and I am not sure where to start.
Reading Tab Delimited File Into Database
I have a .tab file that I need to write to the database. I've read it in, but for some reason it's not reading correctly. I'm truncating the complete database and then reloading it with whatever is in the tab file. I keep getting an error when trying to run my current code which is: Code:
Match Input Value With Values In A Delimited File
I'm very very new to php. I need your help. I have a text file which is ~ delimited. Each line has a name and link. I want to check if the link is similar to my input and if it is then return the name.
Importing To DB From Pipe Delimited Text File
I am trying to make a PHP script that will import data from a pipe delimited text file in to a database. The problem I am having is that the fields have long descriptions in them and there are multiple line breaks for paragraphs. They contain HTML codes as well (<B>). The multiple line breaks are causing it to import the data strange, putting data in the wrong fields and totally missing some data as well. Here is what the text file Code:
Stripping Quotes Out Of A Comma Delimited File?
I have a flat file that I'm trying to stick into a MySQL database. One record per line, multiple fields per record, and many of them are null fields which are just double quotes without a space between. It's probably nothing really major for people who have done this before, but I'm a bit stumped. The file is comma delimited. Every field is surrounded by double quotes. I've done quite a bit of searching, on the php site and elsewhere, but I can't seem to get it to strip the quotes out so I can explode the file line by line to grab the fields.
Update Table While Insert Data To Another Table
it seem like mine coding din work. [php]<? include("checkin.html"); $conn=mysql_connect('localhost','root','') or die ('Could not connect to server'); $today = date("Y.m.d"); mysql_select_db('hms', $conn); $ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn); if( $ok ){ $up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID'); if(mysql_affected_rows( $up ) == 1) { echo'Checked IN!' }else { echo'No such student to check in' }} else { echo'Check In FAILED, please check again'}?>[php]
Insert Into Table Using For Loop
i managed to get bits a pieces and managed to get this script to nearly work. I put together this script which a)gets a no. of fields to create 2) creates those fields 3) on submission it checks for blank fields & may display error msg 4) also it checks in the db for duplicates & may display error msg 5) if all good it submits to db. Here comes my dilemma. 1, 2, 3 and 4 work fine however the final part 5 doesnt work at all. 5 works if 3 and 4 are taken away for some reason. I am sure there i am missing something. Can someone please take on the challenge and direct me to where i could be going wrong. PHP Code:
MS Access And Php- Insert Row In A Table
I am not able to insert a row through a form in my database which is in Access.Please see my code below and help..Select works O.K. but inserting through form is a problem.This is form1.php.here I am inserting the values.This form has action process.php......
Insert Data To A Table
I just can't figure out why it isn't sending the data to the table, I've check the names over and over, all the info is parsed correctly, but it falls flat at: $result = mysql_query($sql);
Switch And Insert Into Table
I want to build a questionnaire with php. My problem is that the second page where i insert the results into the database doesnt work. Code:
Mulitiple Table Insert
I have a table that when you add a new department it will add the name to the table and assign the row and id based on an auto_increment column. From there you need to get the value of the last insert id. SO what I did was use the msql_insert_is() function. and assigned it to a variable. I then used that variable in my next query because this vaule is a forigen key in another table. Here is my code it should be exectued if you where to post this page with the value of $department_id = "" then the section of script in question will execture. Essentially need it to grab this id number and then place it into 2 more insert statements that should execute immediately after the first insert statement. Then only insert id that I would need is the one produced in the first insert statement what an auto increment value is assigned to the same table as the department_name Code:
Insert To One Table, Update To Another
I'm trying to do two queries at once utilizing data from a form. I'm creating a new row in one table, and I need to reflect the ID number and other supplementary data to an existing record in another table. Is there a way to string two queries together so they execute at the same time? Here's what I've been trying so far: Code:
Insert Multiple
I am having a heck of a time trying to insert multiple entries into same table. This is what I am trying to do: insert into table value ('".$adminname."','".$subject."','".msg.'").... Value: $adminname = Name1, Name2, Name3 etc... $subject = Any Subject Here $msg = The message a visitor types here
Insert Into Table Via Assoc Array
I am trying to populate data from an array into a table, but i cant figure out what i am doing wrong. //mysql query $sql = "SELECT charge_location.dept_code, charge_location.week, Sum(charge_location.total_hrs_paid) AS sum_of_total_hrs_paid, Sum(charge_location.hrs_non_chargeable) AS sum_of_hrs_non_chargeable FROM charge_location GROUP BY charge_location.dept_code, charge_location.week"; $result = mysql_query($sql); $num_results = mysql_num_rows($result); //populate the stats_table for($i=0; $i<$num_results; $i++){ $row = mysql_fetch_array($result); mysql_query("insert into stats_summary values( ($row[dept_code]), ($row[week]), ($row[sum_of_total_hrs_paid]), ($row[sum_of_hrs_non_chargeable])) "); } PS i get no errors when it executes, just fails to populate the table.
Using An Array To Insert Data Into A Table.
This works: $col1 = 2; $col2 = 2; $col3 = 2; $col4 = 2; $query = "INSERT INTO test (a,b,c,d) VALUES ($col1,$col2,$col3,$col4)"; and this does not $col = array(2,2,2,2); $query = "INSERT INTO test (a,b,c,d) VALUES ($col)";
How Do You Insert A Value From Drop Down List To SQL Table?
I am a bit new to PHP and SQL so this may seem like a dumb question. I have already created a drop down list as part of a form which is automatically populated with values taken from a separate database. When a user goes onto this page and either leaves the default value or selects a value from the drop down list and presses the submit button, I would like that selected value to be stored into a database which I have already created in SQL. Just to let you know that I can do the above using a text field but just don't know how to do it with drop down list. If your going to explain any coding then it may help if I give you the names of certain items that are involved. Database is called "Company" Field within database is called "Name"
Insert Into Multiple Tables
I'm trying to insert data collected on a form into two tables into my database. I know the SQL statements work because I tested them individually, but I keep getting the error "Couldn't execute query 2". Code:
Insert Multiple Rows At Once
i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d', '$e')"; I want to insert 5 rows at a time in the database, but it only inserts every 5th record. For example: 1. AA 2. AB 3. AC 4. AD 5. AE I only find 5. AE back in the mysql with id 1. How can I insert multiple rows at once ?
Multiple Insert Problem
I'm writing a program for our ice hockey team, and still being rather new, I guess I don't know everything. What my problem is, is that I want to have 3 inserts, all listed in here as $query The problem is, is that the first one writes to the Game database, but the other two don't. Both tables Game and GameData are listed in this format (capitals) on the mysql table. I've done plenty of searches, and cannot find out why this is not working. PHP Code:
Multiple Insert Or Update
I have this form and i want to do a multiple insert using checkboxes. The values are fetched from a tbl1 and will be inserted into another table tbl2. I want to get only those fields where checkbox next to it is selected Code:
Insert Into Microsoft Access Table Using ODBC
The following lines of code don't return an error but they also do not insert the row into the database: $SQLText="Insert into member (MailingID, MemberID, [File As], EMail, LetterID, AudienceID, DateSent, Sent) Select $MailingCode, $row[0], '".$row[5]."', '".$row[6]."', $LIDToInsert, $AIDToInsert, '".$DateSent."', 1;"; print '<br>'.$SQLText; $rs_upd=odbc_exec($link, $SQLText); if (!$rs_upd) die("Couldn't update database"); I've tested the resulting $SQLText string in Access directly and it works find there so this must be a PHP or ODBC issue.
Insert New Row In Table After 5 Lines - Detect Whole Number?
I have a script that loops through an image directory to create a table of thumbnails. I want to start a new row after every fifth thumbnail. I assumed there was a function which identified whole numbers, but alas, there doesn't seem to be. How do I produce a short version of my long, working version below. PHP Code:
Insert Empy Variable Into Mysql Table
I've got a form in which a couple of the address fields can be empty when the form is submitted... I haven't actually managed to get the Insert statement to work yet (see other post..), but I know this seems to also be causing problems. I have set up the table fields for these 2 address form fields to be Yes under the NULL column, but it still gives the almighty: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' , London, W1, UK, 9991, 007, 'warstormer@hotmail.com'' at line 1 Code:
Php Script To Perform Mysql Table Insert
I'm trying to have my php script insert into 2 tables at once, it's for a picture database. Is it actually possible to insert into 2 tables at once? If so what would the sql statement look like.
Insert Multiple Arrays Into Mysql
I am having problems writing the code to generate my SQL INSERT query. I have 3 arrays and one static variable ($cat_number): $track_name[] $music_link[] $track_number[] $cat_number Should I be using a foreach command. I know how to insert multiple values but its generating the query that i'm not sure about. INSERT INTO table (track_name, music_link, cat_number, track_number) VALUES (var1,var2,var3,var4), (var5,var6,var7,var8), (var9,var10,var11,var12); I don't want to store the actual array in the dataabase, I am just using an array to catch the data.
Multiple PHP/MySQL INSERT Statements
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover - 03/03/2004)"); INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite. Good food.", " (Minnie Mouse - 01/03/2004)"); etc etc These have been parsed from a review form that a client already submitted. What I need to do now after I have reviewed the information for appropriateness and grammer is to insert it into my MySQL database. I would write single line entries like this: // Set Mysql Variables $host = "localhost"; $user = "root"; $pass = ""; $db = "rest"; $table = "reviews"; // Connect to Mysql, select the correct database, and run the query which adds the data gathered from the file into the database mysql_connect($host,$user,$pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); $add_review = "INSERT INTO $table values('','$rname','$umeal','$ucomment','$uname')"; mysql_query($add_all) or die(mysql_error()); But how would I write the $add_review to read each line of the add2db.txt and enter it as a separate entry?
Insert Multiple Rows From One Form
I have one form submitting a dynamic amount of identical entries depending on how many are generated from the query for the specific date. Each form "set" consists of four values, qid#, a#, a#, a#. So for example, three sets of these equal forms will create the following values: qid1, a1, a2, a3 qid2, a4, a5, a6 qid3, a7, a8, a9 .... etc I would like to insert each of these "sets" of values as a new row in my table. Right now I'm using the following code and I'm having problems: Code:
An SQL Query To Insert One Child For Multiple Parents
Let's say we have two tables: Table 1) Category [fields= categoryid,categoryname] Table 2) Sub-Category[fields= subcategoryid,categoryid,subcategoryname] Let's say: There are 5 entries in Category Table and that are 1,Books 2)Games 3)Toys 4)Computers 5)Cars now, if i want a subcategory of category "Cars", simply i add a subcategory in it with categoryid=5 thats no problem. i want a MYSQL query that could allow me to add a subactegory for all those 5 categories in one Query. so that query enters 5 new rows in table "subcategory" where subcategoryid,subcategoryname remains same but categoryid is 1,2,3,4,5 respectively.
Insert Multiple Variables Into A Database Quickly
I've just started using PHP and have written a small script to insert 10 variables into my database, e.g: $query = "insert into items values ('".$q1."', '".$q2."', '".$q3."', '".$q4."', '".$q5."','".$q6."', '".$q7."', '".$q8."', '".$q9."', '".$q10."')"; The problem is, I will eventually need 300 questions so I don't want to list them all individually. How can change this snippet of code so that it says something along the lines of "please insert all the variables q1-q300 into the database"?
Multi Table Insert Delete Select Function Needed.
I am going nuts here and I know with all the functions out there, there must be an easier way to do this. Maybe someone can point me to the right tutorial or even show me how to do this. I have a $main_id and many $sub_id tables and like to “SELECT to view” INSERT and DELETE those. UPDATE must not be but would be nice. Here is how it looks:
Multiple Table Search
I've been playing around with this and I can't quite find the right answer. I have two tables. One has a list of apartments with each having an id. The other has a list of the apartment's bedroom configurations, each one starts with the same id of the apartment. Now I'm using LEFT OUTER JOIN to get all of the apartments and their configuration. But now I get a list of every apartment, plus each of it's configurations. What I want is just the list of the apartment itself. Instead of the results coming back with 6 of one apartment, I just want it to show me the apartment once... Anyone?
Multiple Table Pull
$result = mysql_query("SELECT $tb1.fname FROM $tb1, $tb4 WHERE $tb1.email = '$T1' AND $tb1.pass = '$T2' AND $tb1.unum=$tb4.unum",$db) or die(mysql_error()); $_SESSION['myfname'] = mysql_result($result,0,"$fname"); The error I get is: Warning: mysql_result() [function.mysql-result]: not found in MySQL result index 6 in /home/xratedda/public_html/loginout.php on line 39 I know, it looks like I am only grabbing one thing and don't need different tables, but I am trying to figure out how to do this with just one item, before adding the rest.
Linking Multiple Records From Another Table
I'm not sure I'm even thinking about this the right way, but here goes: I have a table of users. Each one of these users may be associated with none, one, or many records in another table I call a todo table. table user = 'id', 'name', 'bla bla bla','todo_list' table todo = 'id','title','other info' Suppose user 'id=1253' has on his todo list items 756,241, and 672. I create a string 756,241,672 and store that string in the user's todo_list field. Then when I want to display the todo items I get the string with a query, bust it up into an array, iterate the array and query the todo table. I have a gut feeling I'm making it way more complicated than need be. But I can't think of any other way to do it
Inserting Multiple Transactions Into One Table
I am trying to insert multiple transactions into one table. Basically the user fills out a form and then checks a few boxes. What I need is to have a seperate row inserted into a table for each checkbox they check. <input type=checkbox name=id value=1> <input type=checkbox name=id value=2> <input type=checkbox name=id value=3> <input type=checkbox name=id value=4> So if they would check all 4 boxes then it would insert 4 seperate rows into the table... The checboxes are queried from a database so the amount of checkboxes shown can change anytime as well as the value. Right now it just inserts one transaction which is for the last id.
Multiple Queries That Print To The Same Table?
I have a query that is hitting the same table for the same info just by different means. 1st query looks info up by position. 2nd query looks info up by name. At this moment the 2nd query works. If I free the result for the 2nd query before it starts then the 1st query works and the second one doesn't. Code:
Passing Multiple Table Values
I have a products table that I have created from a query, but I need to update the information based on quatity. What I am confused about is how to pass the multiple values to another page when they have the same variable names. Code:
Multiple Table Search With Mysql
i want to search multiple tables to see whether a certain user has posted more than three times in any category in my database. how can i do a search for the same field in different tables?
Query String With Multiple Values In One Table
I'm having trouble with the syntax on a query string, and haven't been able to find any posts or tutorials that seem to address this specific type of query. I have a table named "items" with a field for "name" In the "name" field, I have several different entries (actual data), including John, Mark, Sue, Brian, Lucy, etc. In the specific page I'm building, I want to query the database and return the data for more than one person, but not everyone. It seems the query string should be: $query="SELECT * FROM items WHERE name='Brian' AND name='Sue' ORDER BY name ASC"; However I get errors. If I remove the "AND name='Sue'" it returns data for Brian just fine, and if I remove "name='Brian' AND" it returns data for Sue, but I can't get it to return the data for both of them.
Selecting Multiple Columns In The Same Table For A Graph?
I need to select all of the columns and arrage them in to groups so def is one group and distance another and elevation...etc all within the same graph, these would be coloured so distance1 would be the same colour as elevation1 etc. Code:
|