This topic is locked

compare two fields from 2 tables

8/5/2008 7:07:10 AM
PHPRunner General questions
F
fryon author

Is it possible in phprunner to compare two fields in two tables before entry into the database?
I have two tables:
Table orders (id, itemNo, itemqty)

Table catalog (idNo, itemCode, qty)
To accept data into "orders" table,
IF itemNo>=qty THEN "No enough stocks"
Else, insert record into orders table.
Is this possible?
Regards Masters. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=9201&image=1&table=forumtopics' class='bbc_emoticon' alt=':rolleyes:' />

J
Jane 8/5/2008

Hi,
use Before record added event on the Events tab for this purpose.

Here is a sample:

global $conn;

$strSQL = "select * from catalog where idNo=".$values["itemNo"];

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

if ($data = db_fetch_array($rs))

if ($values["itemqty"]>=$data["qty"])

{

$message = "No enough stocks";

return false;

}

return true;

F
fryon author 8/5/2008

Hi,

use Before record added event on the Events tab for this purpose.

Here is a sample:


Thanks for a prompt reply Jane, but it didn't worked out. I have my item in catalog with itemCode=123456, with qty=100,
And i did try adding orders where itemNo=123456, orderqty=105, Still data was added into order table which is supposed to be rejected since orderqty>qty.
I think i dont need a SELECT * FROM catalog, since im dealing with that itemCode=123456 only.
Any help out there?
More power.

J
Jane 8/5/2008

Try to use this code:

...

$strSQL = "select * from catalog where itemCode=".$values["itemNo"];

...