本文介绍了PHP警告:mysql_query()期望参数1为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望能为你们中的一个人提供一个快速的食物.
Hopefully a quick one for one of you out there.
我遇到了两个与:有关的错误:
I'm getting two errors that are related to :
我的代码如下...
<?php
#
# FUTURE EVENTS
#
# PAGE SELECTOR FUNCTION
function pageselector ($pagenum, $pages, $arg, $perpage) {
#page we're loading
if (!$pagenum) $pagenum=1;
# PRINT PAGE SELECTOR
$pages=ceil($pages/$perpage);
#last = prev page unless we're already at page 1
if ($pagenum==1) {$last=1;} else {$last=$pagenum-1;}
#next = next page unless we have no more pages to display
if ($pagenum==$pages) $next=$pagenum; else $next=$pagenum+1;
#create page numbers
$pagenumbers="";
for ($i=1; $i<=$pages; $i++) {
if ($i==$pagenum)
$pagenumbers.=$i.' ';
else
$pagenumbers.="<a href=\"?pagenum=$i$arg\">$i</a> ";
}
# create page num in case of blank page
if (!$pagenumbers) {
$pagenumbers="<a href=\"?pagenum=1$arg\">1</a> ";
}
print <<< pageSelector
<div class="pageselector">
Page:
<a href="?pagenum=1$arg">«</a> <a href="?pagenum=$last$arg">‹</a>
$pagenumbers
<a href="?pagenum=$next$arg">›</a> <a href="?pagenum=$pages$arg">»</a>
</div><br />
pageSelector;
return $pagenum;
}
$perpage=3;
$now=time()-(1 * 24 * 60 * 60);
$sql="SELECT count(*) AS total FROM event_tbl WHERE dates>'$now'";
$sql=mysql_query($sql);
$pagenum=pageselector ($pagenum, $sql['total'], '', $perpage);
$eventlist=array();
$sql="SELECT * FROM event_tbl WHERE dates>'$now' ORDER BY dates ASC";
$sql=mysql_query($sql);
$sql=mysql_fetch_array($sql);
while ($sqlevent=mysql_query($sql)){
$eventlist[]=$sqlevent['id'];
}
for ($i=0; $i<$perpage; $i++) {
$tempid=($perpage*($pagenum-1))+$i;
$sql="SELECT * FROM event_tbl WHERE id='$eventlist[$tempid]'";
$sql=mysql_query($sql);
$smallevent=mysql_query($sql);
if ($smallevent['dates']==0)
break;
print '<div>';
$smallevent['description']=strip_tags($smallevent['description'], '<img>');
$shortdescription=substr($smallevent['description'], 0, 350);
print '<span style="font-size: 14px;"><b><a href="./event.php?event='.$smallevent['id'].'">'.$smallevent['name'].'</a></b> - <b>Date:</b> '.date('j/n/Y', $smallevent['dates']).' - <b>Price:</b> ';
$places=$smallevent['placesavailable']-$smallevent['placesbooked'];
if ($places>0)
print '£'.$smallevent['price'].'<br />';
else
print '<span class="soldout">SOLD OUT</span><br />';
print '</span><br />';
print $shortdescription.'...';
print '<br /><br />';
print '<a href="./tellfriend.php?event='.$smallevent['id'].'"><img src="./images/link-tellfriend.png" alt="" /></a> ';
print '<a href="http://maps.google.com/maps?daddr='.$smallevent['postcode'].'" target="_blank"><img src="./images/link-directions.png" alt="" /></a> ';
print '<a href="./event.php?event='.$smallevent['id'].'"><img src="./images/link-info.png" alt="" /></a> ';
if ($smallevent['bookless']==0 & $places>0)
print '<a href="./bookevent.php?event='.$smallevent['id'].'"><img src="./images/link-book.png" alt="" /></a> ';
print '</div><br /><br />';
}
?>
两条错误线是:
while ($sqlevent=mysql_query($sql)){
$eventlist[]=$sqlevent['id']; }
$smallevent=mysql_query($sql);
我有一个DB Connect文件(尽管不确定是否触发了它?)
I've got a DB Connect file (Although not sure whether its triggering or not??)
任何帮助表示赞赏.
欢呼
推荐答案
$eventlist=array();
$sql="SELECT * FROM event_tbl WHERE dates>'$now' ORDER BY dates ASC";
$sql=mysql_query($sql);
$sql=mysql_fetch_array($sql);
while ($sqlevent=mysql_query($sql)){
$eventlist[]=$sqlevent['id'];
}
错误非常明显.由于某种原因(我不知道是什么),您再次使用数组调用mysql_query
.
The error is pretty clear. For some reason (I don't know what), you call mysql_query
again with an array.
也许你是说:
$eventlist=array();
$sql = "SELECT * FROM event_tbl WHERE dates > '$now' ORDER BY dates ASC";
$res = mysql_query($sql);
while ($sqlevent = mysql_fetch_array($res)) {
$eventlist[] = $sqlevent['id'];
}
这篇关于PHP警告:mysql_query()期望参数1为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!