Connecting Tech Pros Worldwide Forums | Help | Site Map

Query Value from one table and insert into another table.

Member
 
Join Date: Sep 2006
Location: Atlanta, Ga
Posts: 41
#1: Jan 10 '07
I wonder if possible on page load to query the value of a specific colmn and insert the result into another table. My query looks like so

[PHP]
<?
include("include/session.php");
?>
<?
$usr = "xxxx";
$pwd = "xxxxx";
$db = "xxxxx";
$host = "xxxxxx";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

$result = mysql_query("INSERT INTO audio SELECT pid FROM pix WHERE username='$session->username'");

?>
[/PHP]

I guess the result I'm trying to acheive is that when the page is opened the above query is executed and the pid is queried base of username and inserted into the audio table. I'm not getting any error messages from the query but pid is not being inserted into the audio table..any ideas!

Member
 
Join Date: Sep 2006
Location: Coimbatore, India
Posts: 33
#2: Jan 10 '07

re: Query Value from one table and insert into another table.


What is your version of MySQL?

Subash :)
Member
 
Join Date: Sep 2006
Location: Coimbatore, India
Posts: 33
#3: Jan 10 '07

re: Query Value from one table and insert into another table.


Hi,


Better do the following :

1. Select the value from the table and put into an recordset

2. Then insert the recordset value into the table

Subash :)
Member
 
Join Date: Sep 2006
Location: Atlanta, Ga
Posts: 41
#4: Jan 10 '07

re: Query Value from one table and insert into another table.


Quote:

Originally Posted by subash

Hi,


Better do the following :

1. Select the value from the table and put into an recordset

2. Then insert the recordset value into the table

Subash :)

What is a recordset?
Member
 
Join Date: Sep 2006
Location: Atlanta, Ga
Posts: 41
#5: Jan 10 '07

re: Query Value from one table and insert into another table.


Okay I did a little research on the term and I'm kinda familiar with it now. When I get home I will create the recrord set query.. I will follow up latter..

Thanks you for the sugestion...
Member
 
Join Date: Sep 2006
Location: Atlanta, Ga
Posts: 41
#6: Jan 11 '07

re: Query Value from one table and insert into another table.


I've been hacking away at this for hours with no luck. Record set seem to be a little complicated for the task at hand.
Member
 
Join Date: Sep 2006
Location: Atlanta, Ga
Posts: 41
#7: Jan 15 '07

re: Query Value from one table and insert into another table.


Sorry for leaving this one open so long. This is another one solved. Thanks for the advice. But I found a better solution...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: Jan 15 '07

re: Query Value from one table and insert into another table.


Quote:

Originally Posted by underground

Sorry for leaving this one open so long. This is another one solved. Thanks for the advice. But I found a better solution...

If it's possible, could you share the solution so it may help others in a similar situation. Thanks.
Reply