可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
Hopefully a quick one for one of you out there.
I'm getting two errors that are related to :
Warning: mysql_query() expects parameter 1 to be string, array given
My code is as follows...
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'; $smallevent['description']=strip_tags($smallevent['description'], '
'); $shortdescription=substr($smallevent['description'], 0, 350); print '
'.$smallevent['name'].' - Date: '.date('j/n/Y', $smallevent['dates']).' - Price:
'; else print 'SOLD OUT
'; print ''; print $shortdescription.'...'; print '
'; print '
'; print '
'; } ?>
The two error lines are :
while ($sqlevent=mysql_query($sql)){ $eventlist[]=$sqlevent['id']; } $smallevent=mysql_query($sql);
I've got a DB Connect file (Although not sure whether its triggering or not??)
Any help appreciated.
Cheers
回答1:
$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']; }
The error is pretty clear. For some reason (I don't know what), you call mysql_query
again with an array.
Perhaps you meant:
$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']; }
回答2:
You have to use different names for your variables. Just before the faulty while
:
$sql=mysql_query($sql); $sql=mysql_fetch_array($sql);
The second line assigns the result of mysql_fetch_array
to the variable named $sql
which is then no longer a string. You can use $sql_result
for example.
However, reading your code, I think there's other mistakes. For example, I think you want to do something like this :
$result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ $eventlist[] = $row['id']; }
mysql_query
is for getting the results from the query and then you can read the results with mysql_fetch_array
. You can't use the result of mysql_query
directly. There's plenty of good examples in the linked documentation, you should read them.
The second problem is exactly of the same kind.
回答3:
$sql=mysql_fetch_array($sql); while ($sqlevent=mysql_query($sql)){ $eventlist[]=$sqlevent['id']; }
$sql is an array as mysql_fetch_array returns an array !!! try using other variable !
$eventlist=array(); $sql="SELECT * FROM event_tbl WHERE dates>'$now' ORDER BY dates ASC"; $result=mysql_query($sql,$connection); $sql=mysql_fetch_array($result);
....