Very new to SQL/PHP.
I have a query statement with the following which shows all those records in Category that are equal to 1 to 12.
$dbHOST = 'mydbpath';
$dbNAME = 'mydbName';
$dbUSER = 'admin';
$dbPASS = '12345678';
$pdo = new PDO('mysql:host=' . $dbHOST . ';dbname=' . $dbNAME, $dbUSER, $dbPASS); // create connection
$stmt = $pdo->prepare("SELECT * FROM category WHERE cat_id >= 1 AND cat_id <= 12");
//you should never use *, just call each field name you are going to use
$stmt->execute(); // run the statement
$arr = $stmt->fetchAll(PDO::FETCH_ASSOC); // fetch the rows and put into associative array
print_r($arr); // print all array items, unformatted
?>
I have tested in a program called db Forge Query Builder and I get the results I require from the SLQ query.
The part I can’t work out is what to put on my page to see the array results, at the moment I have the following which returns no results, where am I going wrong?
<?php echo print_r($arr[cat_name]); ?>