php
  • mysql
  • 2011-06-09 63 views 1 likes 
    1
    $today = date('D, d M, Y'); 
    $sql = "SELECT * FROM programs 
         WHERE day1 = '$today' OR day2 = '$today' OR day3 = '$today' OR day4 = '$today' 
         OR day5 = '$today' OR day6 = '$today' OR day7 = '$today' OR day8 = '$today' 
         OR day9 = '$today' OR day10 = '$today'"; 
    if($_POST != "") { 
        $mydate = mysql_real_escape_string($_POST['datepicker']); 
        if($mydate != "") { 
        $sql = "SELECT * FROM programs 
         WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' 
          OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' 
          OR day9 = '$mydate' OR day10 = '$mydate'"; 
        } 
    } 
    

    $mydate結合與日曆....PHP的回聲問題

    如何我PHP的echo日期?

    +3

    值得一提的是,你忘記關閉**第2行**的雙引號 – Marty 2011-06-09 08:10:30

    +0

    也許這是一個還有時間閱讀[數據庫規範化](http://en.wikipedia.org/wiki/Database_normalization)的一些信息,在表中編號列幾乎不是一個好主意;反正常化的反應,這通常會讓你的生活變得更加困難。 – 2011-06-09 09:00:43

    回答

    3

    您在SQL查詢忘記「

    $today = date('D, d M, Y'); 
    $sql = "SELECT * FROM programs WHERE day1 = '$today' OR day2 = '$today' OR day3 = '$today' OR day4 = '$today' OR day5 = '$today' OR day6 = '$today' OR day7 = '$today' OR day8 = '$today' OR day9 = '$today' OR day10 = '$today'"; 
    
    if($_POST!=""){ 
    $mydate = mysql_real_escape_string($_POST['datepicker']); 
        if($mydate!=""){  
        $sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'"; 
    } 
    } 
    
    5

    $mydate如果使用雙引號會自動通過PHP的轉換:你只是錯過了一個雙引號在查詢的末尾:

    $sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'";//Missing double quotes 
    
    0

    你忘了用雙引號,它應該是這樣的$sql = "SELECT * FROM programs WHERE day1 = '$mydate' OR day2 = '$mydate' OR day3 = '$mydate' OR day4 = '$mydate' OR day5 = '$mydate' OR day6 = '$mydate' OR day7 = '$mydate' OR day8 = '$mydate' OR day9 = '$mydate' OR day10 = '$mydate'";

    相關問題