phpmyadmin - Add value into database plus 1 -


in database have:

row id - driver id - log id.

row id unique , auto-increments. want log id unique each row has driver id.

for example row inserted driver id 1 want row have log id of 1 next time row inserted driver id 1 want have log id of 2.

how can achieve this?

by way database using phpmyadmin.

----------------edit----------------------

this have in php now, says:

on webpage: incorrect integer value: '' column 'finescost' @ row 1

and dump variables , this: string(2) "16" string(2) "16" string(2) "16" dont understand why saying incorrect integer value , why saying undefines because defined.

in php error log: [19-jul-2013 10:44:18 europe/minsk] php notice: undefined variable: finescostp‌ost2 in c:\inetpub\wwwroot\hosting\dan\jwt\drivers-log-send.php on line 336 [19-jul-2013 10:44:18 europe/minsk] php notice: undefined variable: travelexpensespo‌​st2 in c:\inetpub\wwwroot\hosting\dan\jwt\drivers-log-send.php on line 336

///php insert driver's bank details bank database

session_start();   $host=""; // host name $username=""; // mysql username $password=""; // mysql password $db_name=""; // database name $tbl_name="jwtdriversbank"; // table name  $un = ""; $usrname = ""; $usrpass = ""; $userid = "";  mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db");  if(isset ($_session['usrname'])) {     $usrname = $_session['usrname']; } else {     echo "4"; }  //var_dump ($usrname);  if(isset ($_session['usrpass'])) {     $usrpass = $_session['usrpass']; } else {     echo "5"; }  $sql="select * jwtdrivers username='$usrname' , password='$usrpass'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result);  $userid = $rows['id'];  //var_dump ($userid);  if($userid == "") {     echo "3"; } else {              $totalprofitpost = $totalprofit;     $latefeepost = $latefee;     $finescostpost2 = $finescost;     $travelexpensespost2 = $travelexpenses;     $fuelcostpost = $fuelcost;     $cargodamagepost = $cargodamage;     $truckdamagepost = $truckdamage;      var_dump ($totalprofitpost);     var_dump($finescostpost2);     var_dump($travelexpensespost2);      $sql="insert jwtdriversbank2 (driverid, logid, totalprofit, latefee, finescost, travelexpenses, fuelcost, cargodamage, truckdamage) values ('$userid', coalesce((select max(logid) jwtdriversbank2 tab2 tab2.driverid = '$userid'),0)+1,'$totalprofitpost','$latefeepost', '$finescostp‌ost2' , '$travelexpensespo‌​st2' ,'$fuelcostpost','$cargodamagepost','$truckdamagepost')";      $result = mysql_query($sql);      if($result)     {     }     else     {         die(mysql_error());     }  } 

add primary key 2 columns.

it should trick.

look @ link help

alter table table_name add constraint pk_driverid primary key (driverid,logid) 

do not forget drop first primary key because not need no more.

edit : complete other answer

here code insert data.

insert <table_name> values p_rowid, p_driverid, coalesce((select max(log_id) <table_name> tab2 tab2.driver_id = p_driverid),0)+1; 

that should close question.

you did not defined variable because php can't read them. opened program inside vim editor , found "<200c>" char inside $finecostpost2 in sql query. have change make work.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -