This topic is locked

count value from detail table

3/12/2009 4:11:12 PM
PHPRunner General questions
D
danaci author

hello,
I have two tables.

a-master table

sno int

name varchar

..

..
b-detail table

sno2 int

sayac int

tarih date

..

..
master and detail table relating with sno and sno2
my problem is
when new record, must sayac value is count(sno2)+1 from detail table.
before record event is
$str = "select count(sno2) from detail where sno2 = '{$values["sno"]}'";

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

$data = db_fetch_numarray($rs);

echo $data[0];

$values["sayac"]=$data[0]+1;
but I have 0 value in sayac.

what is problem this code?
thnx.

J
Jane 3/13/2009

Try to use this one:

$str = "select count(sno2) from detail where sno2 = '".$values["sno"]."'";

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

$data = db_fetch_numarray($rs);

echo $data[0];

$values["sayac"]=$data[0]+1;