Jump to content


Photo

New and trying to copy information from table to table...


  • Please log in to reply
5 replies to this topic

#1 Pyro-Tech

Pyro-Tech
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 September 2006 - 09:43 AM

Hello, i am having an issue and this was one of the first places i thought to try posting.

I have a table in one database named minerva, the table called minerva_users that has the fields of username, user_password, and user_email....i want to write to a different table named accounts and with the fields name, password, email, and an additional field names state with a default of 0

what i want it to do, is copy the username to name, minerva_password to password, and minerva_email to email, and then set the state to 1....

here is my attempt at the query:

SELECT username, user_password, user_email FROM `minerva_users`;
while($row = mysql_fetch_assoc($query)){
    echo $row['name'].'<br />';
    echo $row['`password`'].'<br />';
    echo $row['email'].'<br />';
    SET state='1'
}

when i enter this query, i get this error:

#1064 - 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 'while($row = mysql_fetch_assoc($query)){
echo $row['name'].'<br />'' at line 1

and is there a way to have it do this periodically or anything?

any help would be appreciated....i am needing a seperate table for a script im running, and don't want to cause damage to the table that this info is comming from


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 September 2006 - 12:29 PM

from your code that you posted, your query is just sitting there, not assigned as a string to a variable, or even just used as a string in a query function. Also, according to your post, the field names for minerva_users have minerva_ prefix, right? It should look something like this:

$sql = "SELECT username, user_password, user_email FROM minerva_users";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
    echo $row['minerva_name'].'<br />';
    echo $row['minerva_password'].'<br />';
    echo $row['minerva_email'].'<br />';
    SET state='1'
}

however, you know that in phpmyadmin you can create a new table based off another table, data and all, right?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 07 September 2006 - 12:45 PM

That, and where's the UPDATE statement?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 September 2006 - 12:45 PM

one other thing you may want to check into if you have access to run manual queries is simply to do a SELECT INTO.

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 September 2006 - 01:08 PM

yeah i was gonna eventually point out that if he was going to do it with php, that that's only like half of it. just wanted to make sure he had it working first.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 Pyro-Tech

Pyro-Tech
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 September 2006 - 05:07 AM

ok...i thought the echo part is where it was writing the info it got from the first section

how do i copy the info into a new table then with different field names?


and in all honesty i don't know any MySQL so all the questions asking if i knew something...answer is prolly no  :-[




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users