This topic is locked

Condition for Add control

11/5/2008 2:36:59 AM
PHPRunner General questions
M
maxcolo author

Hi,

I am italian user and I am very happy for Obama victory.

In add new record,I wold to prevent this situation:
If (field name) data(format 11/10/2008) is inferior of Now()

echo" Data incorrect
I already have an event in this page.

I would want to add this control together with this.

Grazie for Your Help
[codebox]global $dal;
//select sum of coperti
$str = "select sum(coperti) as sum_coperti from prenotazioni where data='".$values["data"]."' and id_posto=".$values["id_posto"];
$rs = CustomQuery($str);
$data = db_fetch_array($rs);
//select total seats
$rs2 = $dal->posti->Query("id_posto=".$values["id_posto"],"");
$data2 = db_fetch_array($rs2);
if ($data["sum_coperti"]+$values["coperti"]>$data2["posti_totali"])
{
echo "[b]
";
echo "[color=red]";
echo "I posti totali sono ".$data2["posti_totali"];
echo " E con quelli che hai richiesto superiamo il totale infatti sono ";
echo ($data["sum_coperti"]+$values["coperti"]);
echo "</B>";[/codebox]

J
Jane 11/6/2008

Hi,
here is just a sample:

if (strtotime("now")-strtotime($values["DateFieldName"])<0)

echo "Data incorrect";

M
maxcolo author 11/6/2008

Grazie Jane,

my correct code is

[codebox]if (strtotime("now")-strtotime($values["data"])<0)

echo "Data incorrect";[/codebox]
but as I already insert it before this existing? With correct sintax:

[codebox]global $dal;
//select sum of coperti
$str = "select sum(coperti) as sum_coperti from prenotazioni where data='".$values["data"]."' and id_posto=".$values["id_posto"];
$rs = CustomQuery($str);
$data = db_fetch_array($rs);
//select total seats
$rs2 = $dal->posti->Query("id_posto=".$values["id_posto"],"");
$data2 = db_fetch_array($rs2);
if ($data["sum_coperti"]+$values["coperti"]>$data2["posti_totali"])
{
echo "[b]
";
echo "[color=red]";
echo "I posti totali sono ".$data2["posti_totali"];
echo " E con quelli che hai richiesto superiamo il totale infatti sono ";
echo ($data["sum_coperti"]+$values["coperti"]);
echo "</B>";[/codebox]

J
Jane 11/7/2008

Hi,
you can add your code just before of after your actual code.

One note: if you want to check two or more conditions in the event use following scheme:

$flag=0;

if (first contition)

{

//your code here

$flag = 1;

}

if (second contition)

{

//your code here

$flag = 1;

}

if (!$flag)

return true;// return true if you like to proceed with editing this record

else

return false; // return false otherwise

M
maxcolo author 11/7/2008

Thanck's very, very much

for your time

M
maxcolo author 11/7/2008

My solution

[codebox]

$oggi = date("Y/m/d");

$data_da_controllare=($values["data"]);

if (strtotime($oggi)-strtotime($values["data"])>0)

{

echo "Non puoi prenotare per una data antecedente a oggi.";

return false;

}else{

return true;

} [/codebox]

M
maxcolo author 11/8/2008

It work perfect