例如,我有以下PHP代码:
overflow:auto
问题我想在' nama_lengkap'之间添加字符串。 ' keterangan'所以输出将是nama_lengkap(keterangan)
答案 0 :(得分:2)
您可以使用concat
函数直接在SQL中执行:
SELECT CONCAT(nama_lengkap, '(', keterangan, ')')
FROM Absensi
WHERE DATE(tanggal_kirim) = CURDATE()
ORDER BY tanggal_kirim
或者在PHP中:
$result = mysqli_query ($dbc, "SELECT nama_lengkap, keterangan FROM Absensi WHERE DATE(tanggal_kirim)=CURDATE() ORDER BY tanggal_kirim");
$str = '';
while ($row = $result->fetch_assoc()) {
$str = $row['nama_lengkap'] . '(' . $row['keterangan'] . ')';
// use $str somehow
}
答案 1 :(得分:0)
在您的代码中,只需添加一行代替 for 循环。多数民众赞成。
while ($row = mysqli_fetch_assoc($result))
{
$comma = ",";
$csv_output .= $comma . $row["nama_lengkap"] . "(" . $row["keterangan"] . ")"; //This line instead of for loop
$csv_output .= "\n";
}