Home  >  Article  >  Backend Development  >  php页面传递参数的有关问题,求指教

php页面传递参数的有关问题,求指教

WBOY
WBOYOriginal
2016-06-13 12:18:12733browse

php页面传递参数的问题,求指教

本帖最后由 hisweetgirl 于 2015-04-17 18:09:12 编辑
<br />$query = $db->findall("p_newsclass where f_id='$_GET[cid]'");<br />while ($row = $db->fetch_array($query)) {<br />	$news_class_in.= $row[id].",";<br />}<br />echo $news_class_in=$news_class_in."$_GET[cid]";<br />

就是显示新闻列表,能正确打印出来

但是写到SQL中
<br />$result = mysql_query("select id from p_newsbase where cid in ($news_class_in)");<br />$total = mysql_num_rows($result);<br />pageft($total, 20);<br />if ($firstcount < 0)<br />	$firstcount = 0;<br />$query = $db->findall("p_newsbase where cid in ($news_class_in)  limit  $firstcount, $displaypg");<br />


就出现错误了,获取的cid居然变了


------解决思路----------------------
$news_class_in.= $row[id].",";  
这样拼接出来的结果是会多出一个逗号,可以用substr或者rtrim去掉:
while ($row = $db->fetch_array($query)) {
    $news_class_in.= $row[id].",";
}
$new_class_in = rtrim($new_class_in, ",");

echo $new_class
看你的截图,应该就是cid in()括号中的最后一个逗号引起的sql错误
------解决思路----------------------
URL上是id,怎么用$_GET[cid] 获取?
------解决思路----------------------
最后一张图,错误的sql语句,多了一个“,”。
你这样写循环最后会多一个逗号
------解决思路----------------------
$news_class_in 这个变量最后多了一个逗号。

加一句:
<br />$news_class_in = trim($news_class_in, ',');<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn