C
C
Caspergreen2015-03-11 00:59:44
MySQL
Caspergreen, 2015-03-11 00:59:44

How does fetch_row work in CodeIgniter?

I can't this code

$query = "
  SELECT autor, title 
  FROM dle_post 
  WHERE autor ='' 
  AND UNIX_TIMESTAMP(date)>UNIX_TIMESTAMP('$from') 
  AND UNIX_TIMESTAMP(date)<UNIX_TIMESTAMP('$till')
";
$headings = array('Автор', 'Название', 'Размер');

if ($result = mysql_query($query) or die(mysql_error())) {  
    $objPHPExcel = new PHPExcel(); 
    $objPHPExcel->getActiveSheet()->setTitle('Список загруженных файлов'); 
    $rowNumber = 1; 
    $col = 'A'; 
    foreach($headings as $heading) { 
       $objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$heading); 
       $col++; 
    } 

    // Loop through the result set 
    $rowNumber = 2; 
    while ($row = mysql_fetch_row($result)) { 
       $col = 'A'; 
       foreach($row as $cell) { 
          $objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell); 
          $col++; 
       } 
       $rowNumber++; 
    } 

    // Freeze pane so that the heading line won't scroll 
    $objPHPExcel->getActiveSheet()->freezePane('A2'); 

    // Save as an Excel BIFF (xls) file 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 

   header('Content-Type: application/vnd.ms-excel'); 
   header('Content-Disposition: attachment;filename="userList.xls"'); 
   header('Cache-Control: max-age=0'); 

   $objWriter->save('php://output'); 
   exit(); 
}

Convert to CI similar. More precisely, generate a correct input query in the database). Stupid while ($row = mysql_fetch_row($result)) {

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2015-03-11
@FanatPHP

CodeIgniter is a legacy framework.
Judging by the documentation, it does not have a method for getting data per-line, but there is only a way to get all the lines into an array, and then loop through it. You do it too.

V
Vitaly Kamelin, 2015-03-25
@turboGadjet

So in the docks everything is the same with examples.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question