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

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

QA

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

답변 1

본문


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

 

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


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

 

이렇게 하니까 안되요,, 

 

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

 

이 질문에 댓글 쓰기 :

답변 1

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

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

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


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();
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로