ok...i understood my problem but i do not how to solve!!...
before every thing...this is my full code:
Code: Select all
$sqlw = getAllSubjectsInDbByCatId();
if ($resultw = $mysqli->prepare($sqlw))
{
$resultw->bind_param("i",$cat);
$resultw->execute();
$resultw->store_result();
$rowsw = $resultw->num_rows;
}
$countw=0;
$countw2=0;// count
for($mi=1 ; $mi<$rowsw+1; $mi++)
{
$namePOw = "cat_".$mi;
if($_POST[$namePOw]!="")
{
$arrActivew[$countw] = $_POST[$namePOw];
echo $arrActivew[$countw]."<br>";
/*++++++++++*/
$sql = getCategoriesSsubjectsById();
if ($result = $mysqli->prepare($sql))
{
$rekza = $arrActivew[$countw];
$result->bind_param("i",$rekza);
$result->execute();
$result->store_result();
$rowsZ = $result->num_rows;
}
$countw++;
for($re=1 ; $re<$rowsZ+1; $re++)
{
$namePOw2 = "cat2_".$re;
if($_POST[$namePOw2]!="")
{
$arrActivew2[$countw2] = $_POST[$namePOw2];
$countw2++;
}
}
/*++++++++++*/
}
}
$sql = insertConSub();
if($result = $mysqli->prepare($sql))
{
$result -> bind_param("iiii", $id,$cat,$subject,$subject_sub);
for($ik = 1; $ik <sizeof($arrActivew2)+1; $ik++)
{
$subject = (int)$arrActivew[$ik-1];
$subject_sub = (int)$arrActivew2[$ik-1];
// Execute the prepared Statement
$result->execute();
}
// Close the statement
$result->close();
}
the problem:
the size of arrActivew and arrActivew2 is not the same...
i mean:
Main Cat 1
sub cat 1 | sub cat 2 | sub cat 3
--
Main Cat 2
sub cat 1 | sub cat 2 | sub cat 3
--------
now, when i check Main cat 1 amd check sub cat 1 sub cat 2 from it.....and check Main Cat 2 and check sub cat 1...
the database inserts:
1- Sub cat 1,Main cat 1
2- Sub cat 2,0 (the zero is Main cat 1 because he ran on it before)
3-Sub cat 1 , Main cat 2..
i wish you understood me