Hi Mr Arvin
The problem is that I have one two functions. The first function called, main_catogery() fetches data from the database. The data is two columns(category and catogery_id). The categories are printed on the screen and I take the category_ids to fetch data from another table called category_subject. I get some ids number from that query and that ids are used to get the real subjects from the subjects table. I collect the subjects from that query and store them in an array called $subjects[] and when I pass that array to the next function called subjects() I get null. I mean empty. First I tried to pass it like $subjects($subjects) But it returned empty and again I passed like declaring the array as global . no success. even tried to pass the ids that I got before the array to see if the passing is ok but it is always empty. Below is a section of the code:
include("dbConnection.php");
function Error($message){
printf("<BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><H3><FONT COLOR=\"#CC0000\">
%s</FONT></H3></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>\n", $message);
}
$db = new dbConnection;
$con = $db->getConnection();
if(!$con){
echo "cconnection failed";
exit;
}
if(!($result = mysql_query(" SELECT category_id, category FROM pdc_category", $con)))
die("Error reading the category table");
#if(!($row = mysql_fetch_array ($result)))
#die("Your query returned empty row. check it more closely");
function main_categories(){
global $con;
global $result;
?>
<font face='Arial, Helvetica, sans-serif' size='2'><b>Choose Main Category </b> (Requied)</font>
<table width='440' border='1' cellspacing='0' cellpadding='0'>
<?php
$m_id_count = 0;
$m_id[];
$array[];
while ($row = mysql_fetch_array($result)) {
$m_id[$m_id_count] = $row["category_id"];
$array[] = $row["category"];
$m_id_count++;
}
$count = count($array);
$n_cols = 2;
for ($i = 0; $i <= $count-1; $i=$i+$n_cols){
echo "<TR>\n";
for ($j=0; $j <= ($n_cols-1) ; $j++ ){
echo " <TD>\n";
echo "<input type=\"checkbox\" name=\"main_category[]\" value=\"".$array[$i+$j]."\">";
echo " </TD>\n";
echo " <TD>".$array[$i+$j]."</TD>\n";
}
echo " </TR>\n";
}
echo "</TABLE>";
for($i = 0; $i < $m_id_count; $i++) {
if(!($result1 = mysql_query(" SELECT subject_id FROM pdc_category_subject WHERE category_id = 'm_id[$i]'", $con))){
Error(sprintf("Internal Error %d:%s\n", mysql_errno(),mysql_error()));
exit();
}//close the if
while ($row1 = mysql_fetch_array($result1)) {
$subject_id = $row1["subject_id"];
if(!($result2 = mysql_query(" SELECT subject FROM pdc_lc_subject WHERE subject_id = $subject_id", $con))){
Error(sprintf("Internal Error %d:%s\n", mysql_errno(),mysql_error()));
exit();
while ($row2 = mysql_fetch_array($result2)) {
$subjects[] = $row2["subject"];
} //colse inner while
}//close the second if
}// close the while
}// close the for
}// close function
function subjects(){
global $subjects;
echo " <font face='Arial, Helvetica, sans-serif' size='2'><b> $m_id[0] choose Subject </b> (Requied)</font>\n";
echo " <table width='440' border='1' cellspacing='0' cellpadding='0'>\n";
$count = count($subjects);
$n_cols = 2;
for ($i = 0; $i <= $count-1; $i=$i+$n_cols){
echo "<TR>\n";
for ($j=0; $j <= ($n_cols-1) ; $j++ ){
echo " <TD>\n";
echo "<input type=\"checkbox\" name=\"main_subjects[]\" value=\"".$subjects[$i+$j]."\">";
echo " </TD>\n";
echo " <TD>".$subjects[$i+$j]."</TD>\n";
}
echo " </TR>\n";
}
echo "</TABLE>";
}
NOTE: I first for loop prints the checkboxes successfully but there is nothing when I tried again to print other checkboexes in the subjects() function with the subjects[] array values.
Thanks
cisman mm