show records in multiple cell with defined variables

Topics: Developer Forum, Project Management Forum, User Forum
Apr 17, 2014 at 10:13 AM
session_start();
$code_type_session = $_SESSION['code_type'];
$speciality_session = $_SESSION['speciality_code'];
$start_date_session = $_SESSION['start_date'];
$end_date_session = $_SESSION['end_date'];
$add_specility_query_session = $_SESSION[''];

if($speciality_session != '')
{
    $add_specility_query_session = ' and speciality='.$speciality_session;  
}

$sql = "SELECT * FROM documents WHERE (cdate BETWEEN '".$start_date_session."' AND '".$end_date_session."') AND codes LIKE '%".$code_type_session."|_|%'".$add_specility_query_session;

$Connect = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
$Db = @mysql_select_db($dbname, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());
$result = @mysql_query($sql,$Connect)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());


error_reporting(E_ALL);

require_once dirname(FILE) . '/../Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//Sample Sheet
            $num_rows = mysql_num_rows($result);
            if($num_rows > 0)
            {
                $query_code_name=mysql_query("select title from codes where id='$code_type_session'");
                $data_code_name=mysql_fetch_array($query_code_name);
                $codeName = $data_code_name['title'];
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Code Type');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Code');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Code Description');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Code Count');
if($speciality_session != ''){
$objPHPExcel->getActiveSheet()->setCellValues('E1', 'Speciality');
}
        $array_selcted = array();
        while($row_value = mysql_fetch_assoc($result))
        {
            $all_codes = $row_value['codes'];
            $codesArray = explode($code_type.'|_|',$all_codes);
            $selectiveCodesArray = explode('||',$codesArray[1]);

            $selectCode = $selectiveCodesArray[0];
            $pos = strpos($selectCode, ',');
            if ($pos === false) {
                $array_selcted[] = $selectCode;
            }
            else
            {
                $explodeCommaCode = explode(',',$selectCode);
                foreach($explodeCommaCode as $rs)
                {
                    $array_selcted[] = $rs;
                }
            }   
        }
        $unique_arry = array_count_values($array_selcted);

        arsort($unique_arry);
        $column = 'A';
        $rowCount = 2;
        foreach ($unique_arry as $key => $val) {
            $codeID = $key;
            $countCode = $val;

            $query_codes=mysql_query("select * from code_values where id='$codeID'");
            $data_codes=mysql_fetch_array($query_codes);

            $code_values = $data_codes['value'];
            $code_desc = $data_codes['description'];
$objPHPExcel->getActiveSheet()->setCellValue($column.$rowCount, $codeName);
$objPHPExcel->getActiveSheet()->setCellValue('B2', $codeID);
$objPHPExcel->getActiveSheet()->setCellValue('C2', $code_desc);
$objPHPExcel->getActiveSheet()->setCellValue('D2', $countCode);
if($speciality_session != ''){
    $objPHPExcel->getActiveSheet()->setCellValue('E2', $speciality_session);
    }
}
}



here is complete code i want to show multiple data with their variables. i use column='A' and rowCount=2. i have 10 records in the database but its showing only 1 record. any idea. reply asap. thanx.
Apr 24, 2014 at 7:05 AM
After quick read of your code: $rowCount is not incremented, certain values are always written to the same place.