我需要一些帮助。我一直在摆弄别人的工作,无法弄清楚这个问题。我试图根据日期范围(特别是08/15 /去年到今年08/15)从我们使用的数据库中打印选择,但我不能让它做一个子集,它显然是全部或全部。在我的所有试验中,我都收到了此错误消息 - "警告:mysql_numrows()期望参数1为资源,第59行的/nfs/c04/h03/mnt/80741/domains/jamesgaffigan.com/html/calendar/index_jg.php中给出布尔值
警告:mysql_num_rows()要求参数1为资源,布线在第130行和第34行的/nfs/c04/h03/mnt/80741/domains/jamesgaffigan.com/html/calendar/index_jg.php中给出;
这是处理程序代码:
<?php
//Connect To Database
include("admin/config.php");
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");
//$date = strtotime("20 August" ($current_year-1)); // .= ($current_year-1);
//if ($date = "20 August 2017") {
// echo "yes";}
//($currentDate > $startDate)
$query="SELECT * FROM events WHERE
($end_date BETWEEN '2017-08-15 00:00:00' AND '2018-08-15 00:00:00');
ORDER BY year, month, day LIMIT 0, $maxnum";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
//Get all the data and assign variables
$id=mysql_result($result,$i,"id");
$event=mysql_result($result,$i,"event");
$hour=mysql_result($result,$i,"hour");
$minute=mysql_result($result,$i,"minute");
$ampm=mysql_result($result,$i,"ampm");
$hour_end=mysql_result($result,$i,"hour_end");
$minute_end=mysql_result($result,$i,"minute_end");
$ampm_end=mysql_result($result,$i,"ampm_end");
$month=mysql_result($result,$i,"month");
$day=mysql_result($result,$i,"day");
$year=mysql_result($result,$i,"year");
$month_end=mysql_result($result,$i,"month_end");
$day_end=mysql_result($result,$i,"day_end");
$year_end=mysql_result($result,$i,"year_end");
$month_show=mysql_result($result,$i,"month_show");
$day_show=mysql_result($result,$i,"day_show");
$year_show=mysql_result($result,$i,"year_show");
$location=mysql_result($result,$i,"location");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");
$link=mysql_result($result,$i,"link");
$link_name=mysql_result($result,$i,"link_name");
$description=mysql_result($result,$i,"description");
$html=mysql_result($result,$i,"html");
// removes slashes
$description=stripslashes($description);
//replaces carriage returns with html line breaks
if ($html =="0") {
$description=preg_replace("/\n/","<br>", ($description));
}
// removes the first zero from the hour. We need the zero at first, to keep the numbering in order.
//Of course the number ten needs the zero left in.
if ($hour !="10") {
$hour=preg_replace("/0/","", ($hour));
}
if ($hour_end !="10") {
$hour_end=preg_replace("/0/","", ($hour_end));
}
if (($hour_end =='') && ($minute_end =='') && ($ampm_end =='')) { $end_time ='';}
else { $end_time= " - $hour_end:$minute_end $ampm_end"; }
if (($month_end =='') && ($day_end =='') && ($year_end =='')) { $end_date ='';}
else { $end_date= "- $month_end/$day_end/$year_end"; }
// Here is where we actually print out the events.
echo "
<div style='width:48px; margin: 0px 40px 0px 40px; float:left;'>$month/$day/$year $end_date</div>
<div style='width:224px; margin: 0px 0px 0px 0px; float:left;'><a name=$id></a><span class=\"event_name\">$event</span></div>
<div style='width:220px; margin: 0px 0px 0px 0px; float:left;'>$location</div>";
// email, phone and link is optional, so we have to use a conditional statement. We don't want extra line breaks if these fields aren't used.
if ($email) { echo "Contact email: <a href='mailto:$email'>$email</a>"; }
if ($phone) { echo "Contact phone: $phone"; }
echo"<div style='width:330px; margin: 0px 0px 0px 0px; float:left;'>$description</div>";
if ($link) { echo "<div style='width:198px; margin: 0px 0px 0px 0px; float:left;'><a class='cal_link' href='$link' target='_blank'>$link_name</a></div>"; }
echo"<br><div style='width:1100px; height:16px; float:left;'></div>";
// looks for the next event id and if it exists, prints it out.
$i++;
}
// If there are no scheduled events, print the no events message
if (!mysql_num_rows($result)) {
mysql_connect($dbhost,$dbuser,$dbpass) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname) or die( "Unable to select database");
$query2="SELECT * FROM no_events WHERE id=1";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
mysql_close();
$k=0;
while ($k < $num2) {
$description2=mysql_result($result2,$k,"description");
$description2=stripslashes($description2);
$description2=preg_replace("/\n/","<br>", ($description2));
echo "$description2";
$k++;
}
}
?>
请帮忙!它让我有点疯狂......谢谢!
答案 0 :(得分:0)
此错误消息主要来自无效的SQL语句。如果查询失败,则资源将为false。然后mysql_numrows()
收到false并认为它是布尔值。
查看第一个查询,$end_date
和$maxnum
来自哪里?
在同一个第一个查询中,语句中间还有一个;
。所以首先准备你的SQL有效的东西。它会修复你的错误。