채택완료
PHP 초보가 배열 관련하여 질문있습니다 ㅠ,ㅠ
PHP 처음하는 ㅠ,ㅠ 초보자입니다 ㅠ,ㅠ 이런질문 부끄럽고 죄송합니다 ㅠ,ㅠ
Copy
$sub_main = $this->query("select subject from 테이블 LIMIT 4;"); while($sub_main_rows = $this->fetch($sub_main)) { var_dump($sub_main_rows[subject]);$sub_name = $sub_main_rows[subject];} <td>$sub_name[0]</td><td>$sub_name[1]</td><td>$sub_name[2]</td><td>$sub_name[3]</td>
DB에 맨위4개를 하나 하나씩 출력할려고 합니다/
우선 이렇게 var_dump($sub_main_rows[subject]);
출력하면
"string(50) "ㄷㄷㄷ" string(49) "ㄴㄴㄴ" string(38) "ㄹㄹㄹㄹ" string(44) "ㄷㅋㅋㅋㄷ"
이렇게 나오는데 $sub_name[0]
이렇게 하나하나 출력할려면 어떻게 해야하는지 ㅠ,ㅠ
답변 2개 / 댓글 1개
채택된 답변
+20 포인트
Copy
$sub_main = $this->query("select subject from 테이블 LIMIT 4;"); $i=0; //카운트 초기화while($sub_main_rows = $this->fetch($sub_main)) { var_dump($sub_main_rows[subject]); $sub_name[$i] = $sub_main_rows[subject]; //배열로 누적 $i++; //카운트 증가} <td>$sub_name[0]</td><td>$sub_name[1]</td><td>$sub_name[2]</td><td>$sub_name[3]</td>
답변을 작성하려면 로그인이 필요합니다.