whileループで複数の値を追加するには、レベルごとに2つの値を追加できます.1つはidで、もう1つはタイトルです。whileループで複数の値を呼び出す方法
while ($resultSet = mysqli_fetch_assoc($result)) { $id = $resultSet['id']; unset($resultSet['id']); // <-- add this is if you don't want the id in the final set as it's now the key. $res[$id] = $resultSet; }
またはpickする:私のような複数のフィールドには、すでに連想配列であるだけで
$resultSet
としてそれらすべてを追加し、誰
$limitStart = $_POST['limitStart'];
$limitCount = 15;
if(isset($limitStart) || !empty($limitstart)) {
$con = mysqli_connect($hostname, $username, $password, $dbname);
$query = 'SELECT id, title, caption, description, featured_image, logo, category_sku, industry_sku
FROM works ORDER BY title limit '.$limitStart.','.$limitCount .'';
$result = mysqli_query($con, $query);
$res = array();
while ($resultSet = mysqli_fetch_assoc($result)) {
$res[$resultSet['id']] = $resultSet['featured_image'];
}
echo json_encode($res);
}
ただ1つのID関連データを取得すると、他にも多くのIDがあります。 –
データの格納方法の構造を投稿できますか? –