php - SELECT * FROM table | Only getting the first row out of all -
solved: use fetchall instead of fetch
i have simple sql query works in phpmyadmin, in php first row returned. table has lot of rows, since it's cities of world table (around 44.000 rows).
function getallcities(){ include 'db.php'; $response = json_decode('{"status":"error"}'); if(isset($_session['user'])) { $query = $conn->prepare("select * cities_countries"); $query->execute(); $result = $query->fetch(pdo::fetch_assoc); $response->status = "success"; $response->cities = $result; } echo json_encode($response); }
this gets returned:
{ status: "success", cities: { id: "1", name: "bombuflat, india" } }
as mentioned above, if run query in phpmyadmin, results.
what doing wrong?
if want output results should use fetchall method
$result = $query->fetchall(pdo::fetch_assoc);
find more details , options in manual http://www.php.net/manual/en/pdostatement.fetchall.php
Comments
Post a Comment