Row_Inserting Event

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 877
Location: Switzerland

Row_Inserting Event

Post by mpol_ch »

hello I am trying to use the following code in Row_inserting event. But it does not work. Could someone please have look if I am doing correct things?

My Tables is reservations with following columns: Datum (date), Vom(time), Bis(time).
The content is:
(1) 21.02.2015 02:00 05:00

When I try to enter a new record for same day from 06:00 (Vom) to 11:00(Bis) then I am geting failure message..

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {

$MyResult = ew_Execute("SELECT * FROM reservations
WHERE".'"$rsnew[Vom]"'. "BETWEEN Vom AND Bis");

if (!empty($MyResult)){
$this->setFailureMessage("Sorry, There is A reservation.");
return FALSE;
}else{
return TRUE;
}
}

thanks
mpol_ch


mobhar
User
Posts: 11745

Post by mobhar »

It will always return the failure message, because if you are using ew_Execute(), it will always return the Recordset that never empty (even there are no records found at all).

You should use ew_ExecuteScalar() which will return the first column of the first row. Please read "Server Events and Client Scripts" from PHPMaker Help menu, and scroll to the bottom of the help page, you will see more information and example regarding ew_ExecuteScalar() global function.


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

hello mobhar

I treid with ew_ExecuteScalar(). But now it does not check the condition. all records are inserted. Could you please have a look to my conditon, if it make sense?

thanks
mpol_ch


mobhar
User
Posts: 11745

Post by mobhar »

Do not select all fields, only select one of the fields, for example:

// adjust "YourFieldName" with one of your actual fields name in reservations table
$sSql = "SELECT YourFieldName FROM reservations WHERE '" . $rsnew["Vom"] ."' BETWEEN Vom AND Bis";
echo $sSql; // <-- make sure the output of your SQL is already valid
return FALSE; // <-- remove this line after make sure the SQL above is valid, and if necessary try to execute the SQL using your database manager
$value = ew_ExecuteScalar($sSql);
if ($value <> "") {
$this->setFailureMessage("Sorry, There is A reservation.");
return FALSE;
} else {
return TRUE;
}


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

hello mobhar

thanks a lot. It works and you are great.

mpol_ch


mobhar
User
Posts: 11745

Post by mobhar »

You're welcome. Let's give thanks also to PHPMaker Developer Team for providing us such a great product. Bravo, guys!


Post Reply