In an attempt to learn more php, mysql & json, I downloaded a demo database from: http://www.mysqltutorial.org/wp-content/uploads/downloads/2013/05/mysqlsampledatabase1.zip.
I want to display all customers to echo them out in html table format with edit and delete buttons.
My SQL statement is
"SELECT * FROM customers"
It returns no results and no errors. However, if I change the SQL statement to
"SELECT * FROM customers LIMIT 11"
The first 11 of 122 rows are returned. Using a LIMIT of 1-11 will return results while anything 12 or more returns noting.
Can anyone shed some light on this for me please?
UPDATE: Code for assistance.
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "classicmodels";
$dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password) or die(mysql_error());
$sql = 'SELECT * FROM customers LIMIT 12' or die(mysql_error());
$stmt = $dbh->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
die();
?>
Thank you in advance,
Bg
LIMIT 1-11? Do you want all customers or page two?LIMIT 10will return anywhere between 0 and 10 results depending on how much data is in your database, it just limits the rows returned. I don't know why you're seeing no rows when you have insufficient records. Are you sure this query works correctly independent of PDO? Do you have errors in your code that prevent it from working correctly? You'll want to carefully inspect what's happening between each step of your process.