PHP 将 MySQL 导出到应用发明者的 csv
PHP export MySQL to csv for app inventor
当我尝试将 MySQL table 导出到 csv(使用 php)并在 App Inventor 中将其设为列表时,但列表没有显示。
我的街区:
我的 php 文件:
if ($result = mysqli_query($dbc, "SHOW COLOMNS FROM Absent")){
$numberOfRows = mysqli_num_rows($result);
}
if($numberOfRows > 0) {
$values = mysqli_query($dbc, "SELECT full_name FROM Absent");
while($rowr = mysqli_fetch_row($values)){
for($j=0; $j<$numberOfRows; $j++) {
$csv_output .=$rowr [$j]. " ,";
}
$csv_output .= "\n";
}
}
print $csv_output;
exit;
尝试使用 mysql 本机方法导出到 csv,例如:
SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\’
LINES TERMINATED BY '\n'
FROM users WHERE 1
我不太了解 app-inventor,但至于 sql 查询:
第一个table是"CUSTOMER",你的第二个是:"Absent",是打错了吗?
(您用从 "CUSTOMER" 获得的列数迭代 "Absent" 行,这是您的意图吗?)
您的“$rowr”变量只有 1 列 ("full_name"),因此您可以轻松地:
将 "for loop" 拖放到:
$csv_output .=$rowr [0];
P.S。
php 中的另一种编码方式是:
$result = mysqli_query($dbc, "SELECT column1, column2, column3 FROM Absent");
while ($row = mysqli_fetch_assoc($result))
{
$comma = "";
foreach( $row as $key=>$value )
{
$csv_output .= $comma . $value;
$comma = ", ";
}
$csv_output .= "\n";
}
print $csv_output;
exit;
当我尝试将 MySQL table 导出到 csv(使用 php)并在 App Inventor 中将其设为列表时,但列表没有显示。
我的街区:
我的 php 文件:
if ($result = mysqli_query($dbc, "SHOW COLOMNS FROM Absent")){
$numberOfRows = mysqli_num_rows($result);
}
if($numberOfRows > 0) {
$values = mysqli_query($dbc, "SELECT full_name FROM Absent");
while($rowr = mysqli_fetch_row($values)){
for($j=0; $j<$numberOfRows; $j++) {
$csv_output .=$rowr [$j]. " ,";
}
$csv_output .= "\n";
}
}
print $csv_output;
exit;
尝试使用 mysql 本机方法导出到 csv,例如:
SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\’
LINES TERMINATED BY '\n'
FROM users WHERE 1
我不太了解 app-inventor,但至于 sql 查询:
第一个table是"CUSTOMER",你的第二个是:"Absent",是打错了吗? (您用从 "CUSTOMER" 获得的列数迭代 "Absent" 行,这是您的意图吗?)
您的“$rowr”变量只有 1 列 ("full_name"),因此您可以轻松地: 将 "for loop" 拖放到:
$csv_output .=$rowr [0];
P.S。 php 中的另一种编码方式是:
$result = mysqli_query($dbc, "SELECT column1, column2, column3 FROM Absent");
while ($row = mysqli_fetch_assoc($result))
{
$comma = "";
foreach( $row as $key=>$value )
{
$csv_output .= $comma . $value;
$comma = ", ";
}
$csv_output .= "\n";
}
print $csv_output;
exit;