seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 hello all, I could probably do this in php code in no time, but i figured i'd try to expand my knowledge a little basically i need to do an export of the users table, but the states field in users is tied to the id field of states, so i need the state name not id. so SELECT * FROM `states` then (while its doing this) UPDATE `export` SET `state_address`='state.name' WHERE `state_address`='state.id' like i said this is simple im sure, i'd just like to see it as one query that i can run in my sql tab of phpmyadmin. thanks Link to comment https://forums.phpfreaks.com/topic/164947-solved-sql-update-select/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Author Share Posted July 6, 2009 much less flair, but got the job done sql::connect(); $res=sql::query("SELECT * FROM states"); while($row=sql::getrow($res)){ $id=$row[0]; $name=$row[1]; $res2=sql::query("SELECT * FROM export2 WHERE `state_address`='$id'"); while($row2=sql::getrow($res2)){ $exid=$row2[0]; sql::query("UPDATE export2 SET `state_address`='$name' WHERE `id`='$exid'"); }//end while }//end while Link to comment https://forums.phpfreaks.com/topic/164947-solved-sql-update-select/#findComment-869789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.