다차원 배열 count(1차원 갯수만 추출) 방법

다차원 배열 count(1차원 갯수만 추출) 방법

QA

다차원 배열 count(1차원 갯수만 추출) 방법

답변 1

본문

//최신소식

$sql_latest_news="select wr_subject,wr_datetime from g5_write_latest_news order by wr_datetime desc limit 3";

$qry_latest_news=sql_query($sql_latest_news);

for($ln=0;$latest_news[$ln]=sql_fetch_array($qry_latest_news);$ln++){echo $latest_news[$ln]['wr_subject'];}

 

후에

 

<?php for($lnf=0;$lnf<count($latest_news[$lnf]);$lnf++){ 이런식으로 뽑아내려고 합니다. 

 

그런데 저는 당연히 1차원 배열의 갯수만 뽑고싶습니다.

즉 최신 소식 3개의 row만 뽑고싶은데 count($latest_news[$lnf])는 열의 갯수 (wr_subject,wr_datetime) 2를 출력하고,
 count($latest_news)는 모든 열의 갯수 즉 array1-wr_subject,wr_datetime array2-wr_subject,wr_datetime 4를 출력합니다.
2차원 배열이라도 1차원 배열의 갯수만 (제 상황에서는 '3') 출력하게 하려면 어떻게 해야 하나요?

이 질문에 댓글 쓰기 :

답변 1

//최신소식

$sql_latest_news = "select wr_subject,wr_datetime from g5_write_latest_news order by wr_datetime desc limit 3";

$qry_latest_news = sql_query($sql_latest_news);

for($ln=0;$latest_news = sql_fetch_array($qry_latest_news);$ln++){

  //이곳에서 다차원 배열 및 개수를 넣으세요

  echo $latest_news['wr_subject'];

  $row[$ln] = $latest_news;

  //이곳에서 카운트를 넣어주면 따로 카운트 할 필요가 없습니다.

  $rowCnt = $ln;

}

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 17
© SIRSOFT
현재 페이지 제일 처음으로