테스트 사이트 - 개발 중인 베타 버전입니다

lip처럼 function 반환하는법 질문입니다.. 채택완료

humanb2box 7년 전 조회 2,119

</p>

<p>$start=mktime(0,0,0,date(m),1,date(Y)); // 이번달의 첫날

$start_month=date('Y-m-d',$start);

$firstDay =  $start_month;

$today = date("Y-m-d");</p>

<p>

$sumVisit = sql_fetch(" select count(*) as cnt from 테이블 where vi_date between '".$firstDay."' and '".$today."'");

$sumOnline = sql_fetch(" select count(*) as cnt from 테이블 where wr_datetime between '".$firstDay."' and '".$today."' and wr_70 != 'admin%' ");</p>

<p>

echo "방문자수".$sumVisit['cnt']."
";

echo "상담글수".$sumOnline['cnt']."
";</p>

<p> </p>

<p>

 

이코드인데요,,

 

function set_http($url)
{
    if (!trim($url)) return;

    if (!preg_match("/^(http|https|ftp|telnet|news|mms)\:\/\//i", $url))
        $url = "http://" . $url;

    return $url;
}

 

이런식으로해서

 

echo set_http();

 

이렇게 간단하게 표현하고싶어서요,,

</p>

<p>function firstDay(){</p>

<p>$sumVisit = sql_fetch(" select count(*) as cnt from g5_visit where vi_date between '".$firstDay."' and '".$today."'");

}</p>

<p>echo firstDay();</p>

<p>

 

이렇게 하니까 안되요,, 

 

어떻게 해야한느지 조언좀 부탁드립니다..

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
7년 전

$firstDay , $today 인자로 넘겨 받던가

함수내에서 변수를 재 정의 하던가 

또는 글로벌 변수로 하셔야 합니다~

</p>

<p>function firstDay(){

    

    global $firstDay;

    global $today;</p>

<p> </p>

<p>    $sumVisit = sql_fetch(" select count(*) as cnt from g5_visit where vi_date between '".$firstDay."' and '".$today."'");

    

    return $sumVisit;

}</p>

<p>echo firstDay();</p>

<p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

h
humanb2box
7년 전
global이라는 변수의 용도를 이제 이해했네요,, 감사합니다.
여러모로 도움이 되었습니다 ㅎㅎ

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인