Jump to content

[SOLVED] SQL update select


seventheyejosh

Recommended Posts

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 :D 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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.