-3
所以我有一个excel文件。我有多个查询返回。但是,我需要立即运行所有这些查询并将结果输出到excel文件。PHP - 运行多个查询将结果输出到excel文件
$col = 1;
while($row_data = mysql_fetch_assoc($result)) {
$row = 1;
if ($col == 1) {
$row_headings = array_keys($row_data);
foreach($row_headings as $value) {
$h = preg_split('/X/', $value);
if ($h[0] = $id and $h[2] != null){
$results="select question from lime_questions where sid =".$h[0]." and gid =".$h[1]." and qid =".$h[2]."; ";
echo $results;
//This is where the queries are returned.
//They are echoed to the first cell of the excel file
//They are returned as "query1;query2;..."
//This is where I am messing up.
//I am attempting to run the queries. I have been attempting many different approaches
$query_result = mysql_query($results[0]); //this does not return results of the queries
echo $query_result;
//attempting to show the results in the first cell of the excel file
}
//ideally at this point this foreach would print each query result in its own cell
foreach(mysql_query($results) as $value2){
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value2);
$row++;
}
$row = 1;
$col++;
}
那么问题是什么? – ajtrichards
[**请不要在新代码中使用'mysql_ *'函数**](http://bit.ly/phpmsql)。他们不再被维护,[弃用过程](http://j.mp/Rj2iVR)已经开始。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 –
这是一个电子表格...你可以随时随地写信给任何一个单元格。您不必一次写一行。 –