今天遇到了一个PHP问题,求朋友们帮帮谢了
程序员文章站
2024-01-07 09:42:28
...
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\amp\apache\htdocs\prod\viewcat.php on line 22
遇到这个错误,上网也没找到答案,麻烦你们能帮帮我解决哈,忠心感谢。
我的代码:
require("config.php");
if(isset($_GET['id'])==TRUE){
if(is_numeric($id)==FALSE){
$error=1;
}
if(isset($error)&&$error==1){
header("Location:".$config_basedir."/viewcat.php");
}
else{
$validcat=$_GET['id'];
}
}
else{
$validcat=0;
}
$sql="SELECT * FROM categories";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
if($validcat==$row['id']){
echo "".$row['cat']."
";
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat.
"ORDER BY dateposted DESC;";
$entriesres=mysql_query($entriessql);
$numrows_entries=mysql_nums_rows($entriesres);
echo "
}
else{
echo "".$row['cat']."
";
}
}
require("footer.php");
?>
遇到这个错误,上网也没找到答案,麻烦你们能帮帮我解决哈,忠心感谢。
我的代码:
require("config.php");
if(isset($_GET['id'])==TRUE){
if(is_numeric($id)==FALSE){
$error=1;
}
if(isset($error)&&$error==1){
header("Location:".$config_basedir."/viewcat.php");
}
else{
$validcat=$_GET['id'];
}
}
else{
$validcat=0;
}
$sql="SELECT * FROM categories";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
if($validcat==$row['id']){
echo "".$row['cat']."
";
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat.
"ORDER BY dateposted DESC;";
$entriesres=mysql_query($entriessql);
$numrows_entries=mysql_nums_rows($entriesres);
echo "
- ";
- No entries! ";
- ".date("D jS F Y g.iA",strtotime($entriesrow['dateposted']))."- ".$entriesrow['subject']." ";
if($numrows_entries==0){
echo "
}
else{
while($entriesrow=mysql_fetch_assoc($entriesres)){
echo "
}
}
echo "
}
else{
echo "".$row['cat']."
";
}
}
require("footer.php");
?>
回复讨论(解决方案)
把报错的行标示一下吗
echo "".$row['cat']."
";
提示这里出错了,但是我找不到错误
1,mysql_fetch_assoc 函数是区别大小写的。 $row['cat'] cat 在数据库是否有大小写?
2,mysql_fetch_assoc只能返回一行以字段为索引的数组,建议用mysql_fetch_array()。
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat."ORDER BY dateposted DESC;";
这一句有问题,ORDER BY前少了个空格。
改成以下应该就可以了。
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat." ORDER BY dateposted DESC;";
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat.
"ORDER BY dateposted DESC;";
改成下面的看看
$entriessql="SELECT * FROM entries WHERE cat_id= {$validcat} ORDER BY dateposted DESC";
echo "{$row['cat']}
";试试这个
$entriessql="SELECT * FROM entries WHERE cat_id=".$validcat.
"ORDER BY dateposted DESC ;";
报错的是语法错误
谢谢大家的帮助,我之前把博客重新做了一遍,貌似问题就没有了,最近没怎么上论坛,望大家谅解,谢谢大家的帮助