Help - Search - Members - Calendar
Full Version: CSV Export Not Showing Any Values(?)
Big Red Spark Forums > Big Red Spark.com Forums > Unit Command Climate Assessment and Survey System (UCCASS)
charlesjevans
Not sure how this forum operates but,

I ran a uccass survey of 50 people. The survey used the default Yes/No answer types. Although the results HTML page works OK, when I export the survey as CSV there are no values in it (just the survey questions). The results must exist in the database or the results page could not be generated. Is there another way to get this information out of the database (i.e. the results table)? At this point I am willing to transcribe everything manually if that's what it takes.

Thanks
ellis
It may be that the filter is on.. however
the link on the results as a table at the very bottom export as csv.
other wise the phymyadmin would then export the table as excel via php my admin
hope this helps

QUOTE(charlesjevans @ Jun 26 2008, 09:06 PM) *

Not sure how this forum operates but,

I ran a uccass survey of 50 people. The survey used the default Yes/No answer types. Although the results HTML page works OK, when I export the survey as CSV there are no values in it (just the survey questions). The results must exist in the database or the results page could not be generated. Is there another way to get this information out of the database (i.e. the results table)? At this point I am willing to transcribe everything manually if that's what it takes.

Thanks

charlesjevans
The links on the results page generate a blank csv file (only shows questions). I can export a table from the database directly as a csv using phpmyadmin, but how do I make sense of the output? I'm not able to understand how the data in the output csv files is organized. But thanks...

=======
It may be that the filter is on.. however
the link on the results as a table at the very bottom export as csv.
other wise the phymyadmin would then export the table as excel via php my admin
hope this helps

schun
QUOTE(charlesjevans @ Jun 27 2008, 03:33 AM) *

The links on the results page generate a blank csv file (only shows questions). I can export a table from the database directly as a csv using phpmyadmin, but how do I make sense of the output? I'm not able to understand how the data in the output csv files is organized. But thanks...

=======
It may be that the filter is on.. however
the link on the results as a table at the very bottom export as csv.
other wise the phymyadmin would then export the table as excel via php my admin
hope this helps


Have you tried the following?
http://www.bigredspark.com/forums/index.ph...&hl=results

Sarah
Aaron
I needed to get the export functionality working, but couldn't get my head around the way UCCASS did things so I wrote my own export functionality. You can replace the results_csv.php file with this code. Note you will need to put the database configuration details in this script. It does not read them from UCCASS.

CODE

<?php
$db_host = 'localhost';
$db_username = '';
$db_password = '';
$db_name = '';

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Type: text/plain;");
header("Content-Disposition: attachment; filename=Export.csv");

if (!$link = mysql_connect($db_host, $db_username, $db_password)) {
    echo 'Could not connect to mysql';
    exit;
}

if (!mysql_select_db($db_name, $link)) {
    echo 'Could not select database';
    exit;
}

$sid = $_REQUEST['sid'];
$export_type = $_REQUEST['export_type'];

if (empty($sid) || empty($export_type)) {
  die("No survey id or export type supplied");
}

//get list of questions
$query = sprintf("SELECT qid, oid, question FROM questions WHERE sid = %d AND aid != 899 ORDER BY qid", $sid);

$result = mysql_query(mysql_real_escape_string($query));
while ($row = mysql_fetch_object($result)) {
  $questions[$row->oid] = str_replace("\n"," ", $row->question) ." ({$row->oid})";
  $q_order[$row->qid] = $row->oid;
}

//get results (text)
$query = sprintf("SELECT rt.sequence, rt.qid, rt.answer FROM results_text rt WHERE rt.sid = %d ORDER BY rt.qid", $sid);

$result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
while ($row = mysql_fetch_object($result)) {
  $res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->answer);
}
  
if ($export_type == 1 ) {
  //get results (non-text)
  $query = sprintf("SELECT r.sequence, r.qid, av.value FROM results r JOIN answer_values av ON r.avid = av.avid WHERE r.sid = %d ORDER BY r.qid", $sid);

  $result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
  while ($row = mysql_fetch_object($result)) {
    if (!isset($res[$row->sequence][$q_order[$row->qid]])) {
      $res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->value);
    }
  }
}

else if ($export_type == 2) {
  //get results (non-text)
  $query = sprintf("SELECT r.sequence, r.qid, av.numeric_value FROM results r JOIN answer_values av ON r.avid = av.avid WHERE r.sid = %d ORDER BY r.qid", $sid);

  $result = mysql_query(mysql_real_escape_string($query)) or die(mysql_error());
  while ($row = mysql_fetch_object($result)) {
    if (!isset($res[$row->sequence][$q_order[$row->qid]])) {
      $res[$row->sequence][$q_order[$row->qid]] = str_replace("\n"," ", $row->numeric_value);
    }
  }
}

ksort($questions);
foreach ($res as $res_row_id => $res_row) {
  foreach ($questions as $oid => $question) {
    $output[$res_row_id][$oid] = !empty($res_row[$oid]) ? $res_row[$oid] : ' ';
  }
}

array_unshift($output, $questions);

foreach ($output as $sequence => $response) {
echo '"'. $sequence . '","'. implode('","', $response) ."\"\n";
}
?>
Rednes
Hi, I'm using your script but have a question:

I want a tab-delimited file. So I changed


CODE

echo '"'. $sequence . '","'. implode('","', $response) ."\"\n";


to:

CODE

echo '"'. $sequence . '","'. implode("\t", $response) ."\"\n";



And I changed the filename in the header to "Export.xls".

But instead of going a tab further, it displays a square-like symbol.

Any suggestions?


never mind!:

CODE


echo "". implode("\t", $response) ."\"\n";




biggrin.gif
Rednes
edit: ...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.