php - Update mysql table from a single input to different columns -


i have table called dircode:

create table dircode ( jobcodeid int(11) not null auto_increment, jobcodeserial varchar(255) not null, jobcode1 varchar(255) not null, codestatus1 varchar(60) not null, jobcode2 varchar(255) not null, codestatus2 varchar(60) not null, jobcode3 varchar(255) not null, codestatus3 varchar(60) not null, jobcode4 varchar(255) not null, codestatus4 varchar(60) not null, primary key (jobcodeid) ) 

a user may have upto 4 job codes single serial number. when user inputs dir serial number , 1 code, want particular job's codestatus updated 'used'. rest of data should remain intact. example, when user enters serial number , jobcode3 status of codestatus3 should updated 'used'. please me in writing php code above query.

as said, need update row.

you trying first find out if entered code 1, 2, 3 or 4 (e.g. jobcode3) , set status of code (in case codestatus3). that, (or wouldn't, see below) whole row associative array , figure index out in code (check each jobcode, find code , extract index column name).

then connect mysql server , execute query this:

$columname = "codestatus" . $thecorrectindex; mysql_query(sprintf("update dircode set %s = 'used' jobcodeid = %d", $columname,$dircodeid)); 

check boolean return. if it's false, examine details on error.

(alternatively, put inside sql query, see this question or this , mysql's control flow functions.)

this not solution. might want think creating table codes columns id, status , foreign key column dircode_id avoid putting indices column names (usually not idea).

also, there lot of documentation on around (mysql, php, so).


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -