HOw Do I update from table-2 to table-1
HI what is the wrong in this code?? i have set it 24 hours to update the value in the table.but the problem is if $row is empty then it inserts value from table-2 but after 24 hours it wont update the value.
what I want is it must delete the existing value and insert new one(random value) or it must update the same $row with new value what ever...
if ($row == 0){
mysql_query("INSERT INTO table-1
(regtime,person,location,address,rank,ip,geocode)
SELECT NOW(),person,location,address,rank,ip,geocode FROM table-2 ORDER BY RAND() LIMIT 1");
}
else{
mysql_query("UPDATE table-1 SELECT regtime=NOW(),
person=person,
location=location,
address=address,
r开发者_Go百科ank=rank,
ip=ip,
geocode=geocode FROM table-2 ORDER BY RAND() LIMIT 1");
}
The easiest way is to DELETE the existing rows in table-1 before running the INSERT.
I don't know what the primary key of your table is. I suppose its person?
DELETE FROM table-1 where person in (select person FROM table-2)
INSERT INTO table-1 (regtime,person,location,address,rank,ip,geocode)
SELECT NOW(),person,location,address,rank,ip,geocode FROM table-2 ORDER BY RAND() LIMIT 1
Sorry If I got something wrong, I am not using mysql.
Use REPLACE INTO instead of INSERT INTO
There is no SET in your UPDATE statement, that's why is not doing anything.
See the UPDATE manual page
加载中,请稍侯......
精彩评论