PDA

View Full Version : Mysql database: Editing values in the table help



XeonGX
April 28th, 2007, 14:11
Hello everyone,
I've got a mysql table, with fields in it.


User_____Pass_____Email_____Type
1 1 _____ 1 1 _____ 1 1 _____ 0
1 1 _____ 1 1 _____ 1 1 _____ 0
1 1 _____ 1 1 _____ 1 1 _____ 0
1 1 _____ 1 1 _____ 1 1 _____ 0

and i want to change all the values under the Type field into 1 instead of 0.
its pretty hard to do it manually cuz there is 1000+ values to edit,
can you guys write a code to do this?
:fangel: thank you

krakjoe
April 28th, 2007, 17:03
<?
mysql_connect( "hostname", "username", "password" );
mysql_select_db( "database" );
$result = mysql_query( "UPDATE `tablename` SET type = '1' WHERE type = '0'" );
if( $result ):
printf( 'Query executed, affected &#37;d rows', mysql_num_rows( $result ) );
else:
die( mysql_error() );
endif;

d-j
April 28th, 2007, 18:01
@krakjoe

UPDATE `tablename` SET type = '1' WHERE type = '0'
depend of the type of 'type' field i think. It may work in mysql lately, but i have some problem (3-4 years ago) when 'type' field is numeric. If type of 'type' field is numeric i prefer to :

UPDATE `tablename` SET Type = 1 WHERE Type = 0

XeonGX
April 28th, 2007, 20:43
thanks guys :)
it worked