2016-06-20 2 views
0

헤일로 데이터베이스의 데이터가 특정 텍스트를 숨기기 내 테이블 여기PHP, MySQL은, HTML은, CSS는 - 그것은

sched_id sched_time sched_day emp_id 
1   7:30-9:00 Monday  1 

기본 키, VARCHAR (20), VARCHAR (20)와 각각 외부 키를 가지고 .
데이터베이스의 특정 데이터가 삽입 될 때 텍스트를 녹색으로 표시하고 아직 삽입되지 않은 경우 일반 일반 색만 표시하려고합니다. 여기에 내 작품은 지금까지

<?php 
    $sel_admin = " SELECT * from ehr_schedule where emp_id=".$_SESSION['emp_id']." "; 
    $rs_admin = mysql_query($sel_admin); 
    if($row = mysql_fetch_array($rs_admin)) 
     { 
    ?> 
    <td><?php if ($row['sched_stime']=="7:30-9:00") 
      { ?> 
    <span style="color:green">7:30-9:00</span> //I have already the specific requirement and data in my database, and this display nicely 
    <?php } ?> 
    7:30-9:00 //Although, I want this to be hidden when the requirement above is meeted 
    <?php } ?> </td> 
+3

경고 ** ** PHP를 배우고 계시다면 [mysql_query'] (http://php.net/manual/en/function.mysql-query.php) 인터페이스를 사용하지 마십시오. . PHP 7에서 제거 된 것은 너무 무섭고 위험합니다. [PDO는 배우기가 어렵지 않습니다.] (http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps -pdo-for-database-access /)와 [PHP The Right Way] (http://www.phptherightway.com/)와 같은 가이드가 모범 사례를 설명합니다. 사용자 매개 변수는 ** [제대로 탈출하지 않았습니다] (http://bobby-tables.com/php)이며 악용 될 수있는 [SQL 주입 버그] (http://bobby-tables.com/)가 있습니다. . – tadman

+0

Im에 "Unexpected else"라는 오류가 있습니다. – Noobster

+0

@ tadman 조언을 주셔서 감사합니다 – Noobster

답변

0

당신은 if의 역 발생에 사용할 필요 else입니다. 그래서 :

<?php if ($row['sched_stime']=="7:30-9:00") 
      { ?> 
    <span style="color:green">7:30-9:00</span> //I have already the specific requirement and data in my database, and this display nicely 
    <?php } else {?> 
     7:30-9:00 
    <?php } ?> 

현재보다 약 else, http://php.net/manual/en/control-structures.else.php 읽을 수 있습니다.

if (..) { 
    condition was met, this block executes; 
} else { 
    condition was not met, this block executes; 
} 

또는 여러 가지를 확인하려는 경우, else if를 사용할 수 있습니다

은 그래서 꽤 많이 있습니다.