[PHP x SQLite3]PHPでSQLite3 #3データ取得(SELECT)
PHPでSQLite3 #3データ取得(SELECT)
$tableName="access"; $sql="SELECT id,name,cnt FROM $tableName WHERE name='{$name}' ORDER BY cnt ASC"; $result=$db->query($sql); $tmp=[]; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $tmp[]=$row; } echo json_encode($tmp); $db->close();
データ重複しないように取得
$sql="SELECT DISTINCT name FROM $tableName"; $result=$db->query($sql); if($result===FALSE){ $db->close(); echo $message; exit; } $tmp=[]; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $value=$row['name']; $tmp[]=$value; } echo json_encode($tmp);