답변 3개
채택된 답변
+20 포인트
네 상관없습니다.
하지만 저렇게 쿼리문장을 가져오기보다는 함수내에서 쿼리문을 실행하고 그 결과값을 가져와서 사용하는게 더 낫지 않을까요??
이유가 있으시다면 저게 더 낫습니다..
function eee(){
$sql = "SELECT * FROM gml_write_free WHERE wr_5 = '$aatoday';
$result = sql_query($sql);
$list = array();
for($i=0; $row=sql_fetch_array($result); $i++){
$list[$i] = $row;
}
return $list;
}
print_r2($list);
됩니다.
열고 닫기 잘 맞춰주고,
뜬금없이 등장하는 변수가 없도록 처리하면요.
Copy
// Functions
// - https://www.php.net/manual/en/language.functions.php
// - http://docs.php.net/manual/kr/language.functions.php
function eee($aatoday){
$sql = "SELECT * FROM gml_write_free WHERE wr_5 = '{$aatoday}'";
return $sql;
}
echo eee('값');
Copy
// Variable scope
// - https://www.php.net/manual/en/language.variables.scope.php
// - http://docs.php.net/manual/kr/language.variables.scope.php
function eee(){
global $aatoday;
$sql = "SELECT * FROM gml_write_free WHERE wr_5 = '{$aatoday}'";
return $sql;
}
echo eee();
Copy
// $GLOBALS
// - https://www.php.net/manual/en/reserved.variables.globals.php
function eee(){
$sql = "SELECT * FROM gml_write_free WHERE wr_5 = '{$GLOBALS['aatoday']}'";
return $sql;
}
echo eee();
답변을 작성하려면 로그인이 필요합니다.