对于整个程序PDO来说,命令看起来是不可见的

时间:2017-10-21 21:41:03

标签: php pdo

如果这个cmd是在该日期发生的事件,则该cmd应该使行的背景为紫色,但是它的行为类似于不可见而没有错误报告

$stmt = $db->query('SELECT * FROM eventcalendar where eventDate ='.$dateToCompare.'');
            $row_count = $stmt->rowCount();
        if($row_count !=0) {
            echo "class='event'";
        }
    ("class='event'"; is the background changing cmd)

这是我第一次在这个网站上发帖并尝试联系某人在这种情况下帮助我,它可能看起来有点乱。我会抱怨这个混乱的问题。感谢你的注意力。

例如,第19天和第20天应为紫色; What it looks like db prg在这里(它有一些其他试验的评论):

<?php
 $hostname = "localhost";
 $username = "root";
 $password ="";
 $dbname = "calendar";
 $error = "Cannot connect to database, Please try again later...";
//mysqli_connect($hostname,$username,$password) or die ($error);
 //mysqli_select_db($dbname) or die ($error);
$db = new PDO('mysql:host=localhost;dbname=calendar;charset=utf8mb4', 'root', '');
// $conn = new mysqli($hostname, $username, $password);

//if ($conn->connect_error) {
   // die("Connection failed: " . $conn->connect_error);
//} 
?>
<html>
<head>
 <script>
   function goLastMonth(month, year){ 
     if (month == 1) { 
       --year;
       month = 13;

     }
     --month
     var monthstring = ""+month+"";
     var monthlength = monthstring.length;
     if(monthlength <= 1){
      monthstring = "0"+monthstring;
     document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
     }

   function goNextMonth(month, year){ 
     if (month == 12){ 
       ++year;
       month = 0;

     }
      ++month
     var monthstring = ""+month+"";
     var monthlength = monthstring.length;
     if(monthlength < 1){
         monthstring = "0"+monthstring;
     document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
     }
 </script>
<style>
    .today {
        background-color : #00ff00;
    }
    .event {
        background-color : #9400D3;
    }
</style>
</head>
<body>
<?php
//check if day has passing variable
if (isset ($_GET['day'])){
 $day = $_GET['day'];
}else{
$day = date ("j");
}

if (isset ($_GET['month'])){
 $month = $_GET['month'];
}else{
$month = date ("n");
}
if (isset ($_GET['year'])){
 $year = $_GET['year'];
}else{
$year = date ("Y");
}
//calender valiable
$currentTimeStamp = strtotime("$year-$month-$day");
//get current month name
$monthName = date ("F", $currentTimeStamp);
//Determine how many day there are in this month
$numDays = date("t", $currentTimeStamp);
//variable to count cell in the loop later
$counter = 0;
?>
<?php
if(isset($_GET['add'])){
    $title = $_POST['txttitle'];
    $detail = $_POST['txtdetail'];
    $eventdate = $month."/".$day."/".$year;
    $dildau = date("Y/m/d");
    //$sql = "INSERT INTO eventcalendar (title, detail, eventDate)
    //VALUES ('$title','$detail','date()')";
    $str = $db->query("INSERT INTO eventcalendar (title, detail, eventDate, DataAdaugarii)
    VALUES ('$title','$detail','$eventdate','$dildau')");
    $resultinsert = $str;
    if($resultinsert) {
        echo "Event was succesfully Added...";
    }else{
        echo "Event Failed to be Added...";
}}
?>
<table border='1'>
 <tr>
  <td><input style='width:50px;' type='button' value='<' name='previousbutton' onClick="goLastMonth (<?php echo $month.",".$year?>)"></td>
        <td colspan='5'><?php echo $monthName.", ".$year; ?></td>
        <td><input style='width:50px;' type='button' value='>' name='nextbutton' onClick="goNextMonth (<?php echo $month.",".$year?>)"></td>

 </tr>
 <tr>
  <td width='50px'>Sun</td>
        <td width='50px'>Mon</td>
        <td width='50px'>Tue</td>
        <td width='50px'>Wed</td>
        <td width='50px'>Thu</td>
        <td width='50px'>Fri</td>
        <td width='50px'>Sat</td>
 </tr>
    <?php
  echo "<tr>";

  for ($i = 1; $i < $numDays+1; $i++, $counter++) { 
    $timeStamp = strtotime ("$year-$month-$i");
    if($i == 1){ 
      $firstDay = date ("w", $timeStamp);
      for ($j = 0; $j < $firstDay; $j++, $counter++){ 
      //blank space
      echo "<td>&nbsp;</td>";
      }
    } 

    if($counter % 7 == 0 ){ 
         echo "<tr></tr>";

      }
      $monthstring = $month;
      $monthlength = strlen($monthstring);
      $daystring = $i;
      $daylength = strlen($daystring);
      if($monthlength <= 1){
          $monthstring = "0".$monthstring;
      }
      if($daylength <= 1) {
          $daystring = "0".$daystring;
      }
        $todaysDate = date("m/d/Y");
        $dateToCompare = $monthstring.'/'.$daystring.'/'.$year; 
        echo "<td align='center' ";
        if ($todaysDate == $dateToCompare){
         echo "class='today'";
        }else{
            //$sqlCount = "select * from eventcalendar where eventDate ='".$dateToCompare."'";
            //$result = mysqli_query($conn,$sqlCount); $noOfEvent = mysqli_num_rows($result);
            //$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
            //public PDOStatement PDO::query ('SELECT * FROM eventcalendar where eventDate=$dateToCompare');
            $stmt = $db->query('SELECT * FROM eventcalendar where eventDate ='.$dateToCompare.'');
            $row_count = $stmt->rowCount();
        if($row_count !=0) {
            echo "class='event'";
        }
        }
        echo "><a href ='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a></td>";

  }

  echo "</tr>";

 ?>
</table>
  <?php 
  if(isset($_GET['v'])){
      echo "<a href ='".$_SERVER['PHP_SELF']."?month=".$month."&day=".$day."&year=".$year."&v=true&f=true'>Add Event</a>";
      if(isset($_GET['f'])){
      include("calendareventadd.php");  
  }
  //$sqlEvent = "select * from eventcalendar where eventDate='".$month."/".$day."/".$year."'";
  //$resultEvents = mysql_query($sqlEvent);
  $str = $db->query("select * from eventcalendar where eventDate='".$month."/".$day."/".$year."'");
  ///$resultEvents = $st = $db->query("select * from eventcalendar where eventDate='".$month."/".$day."/".$year."'");
  $allah = $str->fetch(PDO::FETCH_ASSOC);
   echo "<hr>";
  //while($events = mysql_fetch_array($resultEvents)){
      if($events = $allah){
      echo "Evenimente in ziua selectata: "."<br>";
      echo "Title: ".$events['title']."<br>";
      echo "Detail: ".$events['detail']."<br>";
  }
  } ?>
</body>
</html>

0 个答案:

没有答案