###前提・実現したいこと
PHPでデータベースに登録してあるデータを取得して表示させるプログラムを書こうとしています。
以下のようにエラーがでるのですが、228行目がどのように問題なのかが分かりません。
228行目とは、
echo '<p>' . $row["1"]. "</p>\n";
の行です。
ご回答の程よろしくお願い致します。
###発生している問題・エラーメッセージ
Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Sources/public_html/index.php on line 228 Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Sources/public_html/index.php on line 228 Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Sources/public_html/index.php on line 228 Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Sources/public_html/index.php on line 228 Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Sources/public_html/index.php on line 228 ### ```PHP <?php try { $pdo = new PDO('mysql:host=localhost;dbname=xxx;charset=utf8','root','root'); } catch (PDOException $e) { exit('データベース接続失敗。'.$e->getMessage()); } $stmt = $pdo->query("SELECT * FROM sp ORDER BY reg_date_sp DESC LIMIT 5"); while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) { echo '<p>' . $row["1"]. "</p>\n"; } ?>
###補足情報(言語/FW/ツール等のバージョンなど)
PHPバージョン5.6.2 MacOS MAMP内での構築
回答2件
あなたの回答
tips
プレビュー