This topic is locked

To check two fields of two different tables.

12/3/2008 1:14:53 PM
PHPRunner General questions
M
maxcolo author

Hi,

i have this control in Before Add:

[codebox]global $conn,$strTableName;
$str = "select count(*) from ".$strTableName." where data='".$values["data"]."' and id_tavolo='".$values["id_tavolo"]."'";
$rs = db_query($str,$conn);
$data = db_fetch_numarray($rs);
if ($data[0])
{
echo "Il tavolo è già stato prenotato per questa data.
";
return false;
}else{
// if dont exist do something else
}[/codebox]
I would to control another situation, I have two table:
Table1

id_seat

seat_max
Table2

id_prenotation

seat_real
[codebox]if seat_real > seat_max
echo "error messare";[/codebox]
What is the correct code for to insert, in function Before Add? After or Before the previous code?

Tank's

J
Jane 12/4/2008

Hi,
use Before record addedevent for this purpose.

Actual code is dependent on how table1 and table2 are linked.

M
maxcolo author 12/4/2008

Ok, but what is my error code:
[codebox]$rs2 = $dal->tavoli_cena->Query("id_tavolo_cena=".$values["id_tavolo"],"");
$data2 = db_fetch_array($rs2);
$posti_prenotati=($values["posti_prenotati"]);
$data2=($values["posti_max"]);
if ($posti_prenotati>$data2)
{

echo "Il tavolo non dispone dei posti che hai richiesto.";

return false;

}else{

// if dont exist do something else

}

return true;[/codebox]

J
Jane 12/5/2008

Hi,
please see my changes in Bold:

global $dal;

$rs2 = $dal->tavoli_cena->Query("id_tavolo_cena=".$values["id_tavolo"],"");

$data2 = db_fetch_array($rs2);

$posti_prenotati=$values["posti_prenotati"];

$posti_max=$data2["posti_max"];
if ($posti_prenotati>$posti_max)

{

echo "Il tavolo non dispone dei posti che hai richiesto.";

return false;

}

return true;

M
maxcolo author 12/6/2008

tank's, it work very well