insrting from one table to another

Reply

Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

insrting from one table to another

 
0
  #1
Jul 3rd, 2008
hi guys...

i wanna select a single cell (not full row) from one MySQL table and insert the value into another table. The datatype of the (value being extracted) and the (column of insertion) are the same.

somebody pls help...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: insrting from one table to another

 
0
  #2
Jul 3rd, 2008
well i guess the problem is that when i use the command

$res = select * from table where column = 'value';

then AN ENTIRE RECORD is returned into $res.

Then, when i try to assign the value of $res into the other table, i am trying to assign a RECORD into a COLUMN, which is probably causing he error....

in case this is correct, how do i get over this??
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: insrting from one table to another

 
0
  #3
Jul 3rd, 2008
This is how you fetch the record and this is how you insert it.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: insrting from one table to another

 
0
  #4
Jul 3rd, 2008
I have referredd to the links ou indicated, and this is the code i have come up with. But this doesnt seem to work either. I guess the error is based on the usage of ("") , ('') and (``) at different points in the query.

Somebody please clarify... with the code...

MY CODE
  1. $res = select * from table1 where column1 = 'value';
  2. mysql_query("Update table2 set col2 = '$res[`1`]' ");

thx...
Last edited by peter_budo; Jul 10th, 2008 at 9:58 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: insrting from one table to another

 
0
  #5
Jul 3rd, 2008
Okay. This is how you do it.
  1. $res = mysql_query("select * from table1 where column1='value'");
  2. while($row = mysql_fetch_array($res)) {
  3. $value2 = $row['column2']; //assign column2 value to $value2
  4. $query = mysql_query("update table2 set col2='$value2'"); //update col2 in table2
  5. }
  6. ?>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: insrting from one table to another

 
0
  #6
Jul 3rd, 2008
i tried your solution... it does not produce an error, but no UPDATE occurs...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: insrting from one table to another

 
0
  #7
Jul 3rd, 2008
Post your code. Lets see where you have gone wrong.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: insrting from one table to another

 
0
  #8
Jul 4th, 2008
The CODE

  1. // retreiving data from table 1
  2.  
  3. $r1 = mysql_query("Select * from table1 where Column1 = '$test' ") or die(mysql_error());
  4.  
  5.  
  6. // updating the other table
  7.  
  8. while($row = mysql_fetch_array($r1))
  9. {
  10. $value2 = $row['Rate'];
  11.  
  12. $query = mysql_query("update table2 set amt = '$value2' ");
  13. }

plz help...

thx...
Last edited by peter_budo; Jul 9th, 2008 at 7:17 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: insrting from one table to another

 
0
  #9
Jul 4th, 2008
Before while have this.
print mysql_num_rows($r1); I believe, your query doesn't return any records.
The above print statement, will print the number of records found for the select query.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: insrting from one table to another

 
0
  #10
Jul 7th, 2008
Originally Posted by nav33n View Post
Before while have this.
print mysql_num_rows($r1); I believe, your query doesn't return any records.
The above print statement, will print the number of records found for the select query.

Hey nav33n.

You were right. IO tried that command an it showed 0, indicating that no rows were returned by SQL.

Now pls suggest what i shud do...

i shall be highly grateful fr ur co-operation.

thx a lot...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 1356 | Replies: 19
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC