PHP 연산자, 분기문과 반복문; SQL 별명/수식을 이용한 검색

Hyun Seo (Lucy) Lee 이현서·2020년 9월 19일
0
post-thumbnail

2020년 9월 16일

스마트/하이브리드 앱 개발

복습 Entry no.3

PHP

증감 연산자 (Incremental Operators)

$a++

변수를 사용하고 값을 1 증가시킨다.

++$a

값을 1 증가 시킨 후 변수를 사용한다.

$a--

변수를 사용하고 값을 1 감소시킨다.

--$a

값을 1 감소 시킨 후 변수를 사용한다.

ex:

"); --> in this case, $b is would be 5 and $a would be 6. ​ $c = ++$a; --> in this case, $a is increased to 7 first, and then $c is assigned to that value of 7. ​ show_source(__FILE__); --> this shows the php code on a browser. this is good for debugging ?>

you can also just do $a++; by itself, it's a complete statement.

Nowadays in programming, what's most important is that the program is CHEAP and SIMPLE to make. It's not an art. Does not have to be the most intricate, with the best possible genius logic, as long as it works. As long as it's simple to make, and cheap.

In PHP, the division operator (/) gives us a decimal-point, accurate answer (when it's not cleanly divisible).

$a = TRUE;

$b = FALSE;

$d = $a and $b; --> $d = TRUE because the = operator has priority over the and operator. So always use parentheses. And always just use && instead of and when it's not necessary to use and.

$a = "AA";

$a .= "BB"; --> now $a prints out AABB. $a .= $b is equal to $a = $a . $b

2 Main Things for a Programming Language:

  • 분기문 (branch statement) --> if, switch (분기문은 맞지만 조건문 (conditional statement) 은 아님) (also, side note, python doesn't have switch)

  • 반복문 (iteration, loop) --> while, for-loops

*Random HTML Rules:

  • Never forget to write in the tag (should always type @charset "utf-8" on top of css files, too).

  • Don't forget to write <html lang="ko" (or "en")> for 접근성 (accessiblity). So that users get the option to translate the website to their comfortable language.

  • Always write a inside the head, and make it correct and specific, taking care to avoid duplicate titles. This is so important for 시각장애인들.

[Back to PHP]

Functions for checking whether a variable is set or empty/null:

1) empty()

2) isset()

3) is_null()

--> 선생님은 우리가 empty()를 쓰시길 원하심. 제일 intuitive 하니까. But in my past classes at Cornell isset() was also used often.

One format rule: When using POST to retrieve information in the post-formsubmission page, keep the variable name the same as the input name from the form. (ex: $a = $_POST["a"];)

Else - if:

 Else-if is used so we don't run unnecessary if-blocks.

If you were to convert an Else-If block to separate If-blocks (though idk why you would), you can't do if (80 < $reseult <= 90). gotta do $result <= 90 && $result > 80. because it's technically 2 conditions.

Side note: Save the HTML & PHP files as UTF-8 for 인코딩 (Encoding) section if there's any Korean in it.

SQL

To connect to Oracle:

  • go to the sql folder, since that is where the database (.sql) file is, and then type sqlplus st01/1234@oracle. (format: sqlplus ID/PW@TNS명) --> 여기서 TNS는 Transparent Network Substrate이고, this is a proprietary Oracle computer-networking technology. It operates mainly for connection to Oracle databases.

  • 여기서 take note that 지금 내 컴퓨터에 접속한게 아니라 오라클 서버에 접속한거임.

Side note: when you get sql running again by connecting to Oracle server, you always have to run the database file (.sql file) again.

All the columns (aka fields) in a table are referred to as "header".

회사에서 일하게 되면 레포트 뽑는 기술이라고 불리는 이 기술이 아주 중요함. 그래서 data를 출력할때 꼭 nickname (별명)을 써서 뽑아야함. 다른 사람들이 이 정보를 이해할수 있게.

  • ex: SELECT eno 사번, ename 이름, job 업무 FROM emp; --> format: SELECT 컬럼 as "별명", 컬럼 as "별명", ... --> 근데 여기서 as 생략 가능. 이중 인용 부호 ("")도 생략 가능한데 만약 별명에 빈칸 (space) 가 있거나 숫자가 있으면 꼭 이중따옴표 써야함. Or you could replace the space with an underscore ( _ ).

수식을 이용한 검색:

  • SELECT eno 사번, ename 이름, sal*12 "연간 급여" FROM emp; --> (note that people prefer to use 연간_급여 instead)

SQL does all its work in memory. not hard drive. Even when you delete an entry, it is not deleted from the hard drive.

dual --> in Oracle, this is the name you use when you need a dummy table, like SELECT 2+3 FROM dual; . I mean you'd never use it but if you just wanted to use sql to add numbers for some reason lol.

  • SELECT 수식 FROM dual; or SELECT 수식 [별명], ... FROM [table];

*Beware of Reserved Words (예약어): Query가 아닌 type 같은 NUMBER, TEXT 이런얘들도 예약어임.

NVL function:

  • NVL (column, substitution value (치환값)) --> if any entry in the stated column is null, NVL makes it show up as the substitution value instead.

  • NVL stands for Null VaLue. This is one example of something called a 단일 행 함수 (single row function?).

  • used to prevent a null value from messing up the final result value to be null, too.

  • if there's a null in any of the operants, it's called 부정연산. In numerical data especially, there should never be a null value, due to it's vulnerability to fraud (usually with money). And in general, it's just not good to have null in database.

  • ex: instead of sal + comm, do sal + NVL(comm, 0) so that it does not return null. But honestly, if the DB has a NULL, then that means that DB has a bad 설계. It's a goner to begin with.

(just side note: 여기서 급여는 보너스를 포함하지 않는 값이고, 연봉은 보너스를 포함한 값이다.)

0개의 댓글