This topic is locked

Check if record exist in afteradd

8/17/2009 8:39:26 AM
PHPRunner General questions
S
sickacid author

Hi, i've do this code for calculate the

maintenance of the machine based on Km, this code write a line

in another table 'SCADENZIARIO' whit de results, but

What can I do to check if the record already exists ??
This is my working code
global $conn;

$esc = 0;

$next = 0;

$tagli = 0;

$i = $values["KmFine"];

$id = $values["IdTarga"];

//$str = "select SogliaTagliando from anagraficaautomezzi where Id=".$id;

$str = "select SogliaTagliando from anagraficaautomezzi where Id='".$id."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$p = $data["SogliaTagliando"];
do {

if ($i < $tagli)

{

$next = $tagli - $i;

$strSQLInsert = "insert into scadenziario (IdTarga, TipoScadenza, note, ProssimoTagliando, ScadenzaGestita) values ('".db_addslashes($values["IdTarga"])."', 'TAGLIANDO', $i, $next,0)";

db_exec($strSQLInsert,$conn);

$esc = 1;

}
else

{

$tagli = $tagli+$p;

}

}

while ($esc == 0);

J
Jane 8/17/2009

Hi,
I recommend you to publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions of what you want to do.

A
acpan 8/17/2009

You can use MySQL Query such as
mysql_insert_id() to get the last inserted ID which are affected

by previous SQL Insert in the same session.
or
SELECT ROW_COUNT(); to see if rows last SQL insert successfuly.
if does not help, try Jane's advise.
Rgds

acpan

Hi, i've do this code for calculate the

maintenance of the machine based on Km, this code write a line

in another table 'SCADENZIARIO' whit de results, but

What can I do to check if the record already exists ??
This is my working code
global $conn;

$esc = 0;

$next = 0;

$tagli = 0;

$i = $values["KmFine"];

$id = $values["IdTarga"];

//$str = "select SogliaTagliando from anagraficaautomezzi where Id=".$id;

$str = "select SogliaTagliando from anagraficaautomezzi where Id='".$id."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$p = $data["SogliaTagliando"];
do {

if ($i < $tagli)

{

$next = $tagli - $i;

$strSQLInsert = "insert into scadenziario (IdTarga, TipoScadenza, note, ProssimoTagliando, ScadenzaGestita) values ('".db_addslashes($values["IdTarga"])."', 'TAGLIANDO', $i, $next,0)";

db_exec($strSQLInsert,$conn);

$esc = 1;

}
else

{

$tagli = $tagli+$p;

}

}

while ($esc == 0);