comparing info in 2 different tables
Posted: Tue Dec 23, 2008 12:14 pm
hi there,
i'm trying to validate some information, so i need to compare that information by getting the info from one table and then see if that info exists in the other table and if's the same, so far this is all i've got,
is there a better and efficient way to do a validation like this ?
Thanks in advance.
i'm trying to validate some information, so i need to compare that information by getting the info from one table and then see if that info exists in the other table and if's the same, so far this is all i've got,
Code: Select all
$query = "SELECT * FROM `rel_exp`"; //get all the info in this table
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$cod_obj1 = $row['cod_obj'];
$ref_exp = substr($row['ref_exp'], 2, 11);
$dat_env = $row['dat_env'];
$query1 = "SELECT * FROM `content`, `flags` WHERE `content`.`ref`=`flags`.`ref` ..."; // see if i can find $cod_obj1, $ref_exp in those tables
$row1 = mysql_fetch_array(mysql_query($query1), MYSQL_ASSOC);
$ref = $row1['ref'];
$vd = $row1['vd'];
$cod_obj = $row1['cod_obj'];
if(!preg_match("/^[a-zA-Z0-9]{2}[0-9]{9}PT$/", $cod_obj1) || !preg_match("/^[a-zA-Z0-9]{2}[0-9]{9}PT$/", $cod_obj)) {
@mysql_query("INSERT INTO `div` VALUES ()"); // insert some info in div table in case something wrong
if($cod_obj1 != $cod_obj) { // see if cod_obj1 is like cod_obj
@mysql_query(""); // same here
}
}
if(ereg("^[0-9]+$", $ref_exp, $regs) || ereg("^[0-9]+$", $vd, $regs)) {
@mysql_query(""); // same here but to a different field
if($ref_exp != $vd) {
@mysql_query("");
}
}
}
Thanks in advance.