PHP代码
date_default_timezone_set('America/Los_Angeles');
$hostname = "XXXXXXXXXXXX";
$username = "XXXXXXXXXXX";
$password = "XXXXXXXXXXX";
$database = "XXXXXXXXXXX";
$db = mysql_connect($hostname, $username, $password) or die("Could not
connect to database $database $hostname.");
$table = "event";
$field1 = "date";
$field2 = "time";
$field3 = "eventtitle";
$field4 = "evenmessage";
$field5 = "name";
$field6 = "timeentered";
$field7 = "dateentered";
mysql_select_db($database, $db);
function get_events($name,$date,$time)
{ $a="";
$sql = "SELECT * FROM $table WHERE ($field5 = $name AND $field2 = $time) AND $field1 = $date";
$result = mysql_query($sql);
if($result === FALSE) {
return($a);
}
else{
while($record = mysql_fetch_array($result))
{
$a.="Date is $record[field1]: Time is $record[field2] \n $record[field4] $record[field3] - Date entered $record[field7]: \n Time entered $record[field6] \n";
}
return($a);
}
}
date_default_timezone_set('America/Los_Angeles');
$timestamp = time();
$year = date("Y",$timestamp);
$month = date("m",$timestamp);
$day = date("d",$timestamp);
$hour = date("h",$timestamp);
$hour2 = date("G",$timestamp);
$minute = date("i", $timestamp);
$week = date("D", $timestamp);
$apm = date("a", $timestamp);
$hourin=(int)$hour2+1;
$datein=mktime($hourin,0,0,$month,$day,$year);
$na=date('n-j-Y',$datein);
$nana=date('G:i:s',$datein);
$t1=get_events('Joe', $na, $nana);
$t2=get_events('Joanna',$na, $nana);
$t3=get_events('Cub', $na, $nana);
print "$t1"."$t2";
这是PuTTy的输出:
mysql> SELECT * FROM event;
+----------+----------+------------+-------------+------+-------------+-------------+
| date | time | eventtitle | evenmessage | name | timeentered | dateentered |
+----------+----------+------------+-------------+------+-------------+-------------+
| 6-3-2015 | 4:00:00 | dom | | Joe | 15:15:06 | 6-3-2015 |
| 6-3-2015 | 17:00:00 | dom | | Joe | 15:19:34 | 6-3-2015 |
| 6-3-2015 | 19:00:00 | dom | | Joe | 16:02:25 | 6-3-2015 |
+----------+----------+------------+-------------+------+-------------+-------------+
mysql> SELECT * FROM event WHERE (name="Joe" AND time="4:00:00") AND date="6-3-2015";
+----------+---------+------------+-------------+------+-------------+-------------+
| date | time | eventtitle | evenmessage | name | timeentered | dateentered |
+----------+---------+------------+-------------+------+-------------+-------------+
| 6-3-2015 | 4:00:00 | dom | | Joe | 15:15:06 | 6-3-2015 |
+----------+---------+------------+-------------+------+-------------+-------------+
我试过
$sql = "SELECT * FROM $table WHERE ('$field5' = '$name' AND '$field2' = '$time') AND '$field1' = '$date'";
$sql = "SELECT * FROM $table WHERE ($field5 = $name AND $field2 =
$time) AND $field1 = $date";
和
$sql = "SELECT * FROM $table WHERE ($field5 = '$name' AND $field2 =
'$time') AND $field1 = '$date'";
他们都无法打印作品。如果我删除
if($result === FALSE) {
return($a);
}
else{----------------------}
服务器给我警告信息:
> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
/net/laguna/h1/y/ys19931006/public_html/calendar2.php
第40行
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
/net/laguna/h1/y/ys19931006/public_html/calendar2.php 在第40行