Alex Lord
asked on
FetchAll returns Null where all() does not
Here is the ajax call
this is triggered on load.
to run this code -
Now the issue is that it is returning null. but if i change fetchAll to all it returns a row from the database, i need this foreach to fetch all records not just the first one. if i return demo1 instead of customResult i can see there is two records, Please note i can only see this data if i use all() and when i use fetchAll it returns null.
function showCustomProps(){
$('#subaction').val("getCustomProperties");
var data = $('#subaction') ;
$.ajax({
type: "POST",
url: 'controllers/contacts.ajax.php',
data: data,
}).success(function (response) {
console.log(response);
}).error(function (data) {
console.log("erro customProps");
});
} //showCustomProps
this is triggered on load.
to run this code -
$stmt = new Database();
$query = "SELECT cp.id, cp.name, cp.field_type
FROM custom_properties cp
WHERE cp.client_id = :clientID AND cp.viewable='1' AND cp.type = '1'
ORDER BY cp.id DESC";
$stmt->query( $query );
$stmt->bind( ':clientID', $clientId);
$stmt->execute();
$demo1 = $stmt->fetchAll();
foreach($demo1 as $customResult){
$cusData['propertyId'] = $customResult['id'];
$cusData['propertyName'] = $customResult['name'];
$cusData['propertyType'] = $customResult['field_type'];
}//customresult
$response = array(
'subresult' => 'customProps success',
'data' => $cusData
);
break;
Now the issue is that it is returning null. but if i change fetchAll to all it returns a row from the database, i need this foreach to fetch all records not just the first one. if i return demo1 instead of customResult i can see there is two records, Please note i can only see this data if i use all() and when i use fetchAll it returns null.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER