I'm trying this but getting the error message Undefined offset: 0
<?php
try{
$db = new PDO("mysql:host=localhost;dbname=alphabet", 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e)
{
echo $e->getMessage();
die();
}
function select(PDO $db)
{
$alphabet = range("A", "Z");
foreach ($alphabet as $letter)
{
$selector = $db->prepare("SELECT name FROM title", array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$selector->execute();
$fectching = $selector->fetch(PDO::FETCH_ASSOC);
echo "<h3>$letter</h3>" . "<br>";
for($i = 0; $i < count($fectching); $i++)
{
echo $fectching[$i]["name"] . "<br>";
}
}
}
select($db);