Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.