To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Upgrading PHP

Upgrading PHP Issues concerning PHP version upgrades and future releases

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-07-2004, 05:32 PM   #1
srarcade
Member
 
Join Date: Jan 2003
Posts: 39
Multiple Query/Inserts Possible?

I have 3 seperate tables with data, all of which have their own auto_increment ID column. I have to somehow relate all of the IDs into a 4th table given a set of search values. Hopefully my example helps explain.

Simple Example:
SELECT car_id AS carID FROM tbl_cars WHERE str_make = 'Honda' and str_model = 'Accord';
SELECT pet_id AS petID FROM tbl_pets WHERE str_petname = 'Scruffy';
SELECT person_id AS personID FROM tbl_people WHERE str_name = 'Doe, John';
INSERT INTO tbl_relationship (car_id,pet_id,person_id) VALUES ('carID','petID','personID');

So I have a list of some 40,000 entries, each with 3 columns of data. They have all been broken down and put into seperate tables with a bash shell script, now what I want to do is go back over the list again and relate the data in the 4th table, just like my example shows.

The only way i see this possible is if I use php to query my DB 120,000 times, that dosn't seem logical. This sort of thing would only have to be run once though every few months. So any ideas?

Thanks!
srarcade is offline   Reply With Quote
Old 06-08-2004, 01:14 PM   #2
eriksmoen
unset($brain);
 
eriksmoen's Avatar
 
Join Date: Dec 2002
Location: Grand Forks, ND
Posts: 253
PHP Code:
$db = mysql_connect($host,$user,$pass);
mysql_select_db($dbase);
$query=mysql_query("SELECT car_id as carID, pet_id as petID, person_id as personID FROM tbl_cars, tbl_pets, tbl_people WHERE str_make = 'Honda' AND str_model = 'Accord' AND str_petname = 'Scruffy' AND str_name = 'Doe, John'");
while(
$result = mysql_fetch_array($query)){
    
$carID = $result['carID'];
    
$petID = $result['petID'];
    
$personID = $result['personID'];
    
mysql_unbuffered_query("INSERT INTO tbl_relationship (car_id, pet_id, person_id) VALUES ('$carID','$petID','$personID')");
}
mysql_close($db);
... I THINK that should work... but you may have to make some minor adjustments to the query if you have redundant field names...

Hope that helps.
__________________
Nate Eriksmoen
http://www.chillstate.com
eriksmoen is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:48 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.