채택완료

lip처럼 function 반환하는법 질문입니다..

Copy
$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");


$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%' ");


echo "방문자수".$sumVisit['cnt']."<br/>";
echo "상담글수".$sumOnline['cnt']."<br/>";

 

이코드인데요,,

 

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();

 

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

Copy
function firstDay(){

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

echo firstDay();

 

이렇게 하니까 안되요,, 

 

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

 

|

답변 1개 / 댓글 1개

채택된 답변
+20 포인트

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

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

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

Copy
function firstDay(){
    
    global $firstDay;
    global $today;

 

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

echo firstDay();

답변에 대한 댓글 1개

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

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