简体   繁体   English

HTML / PHP的SQL填充导航栏不

[英]html/php SQL populated nav bar not

this is my php code for populating my nav bar through an SQL query. 这是我的PHP代码,用于通过SQL查询填充导航栏。 I'm getting the following error: 我收到以下错误:

Parse error: syntax error, unexpected 'index' (T_STRING), expecting ',' or ';' 解析错误:语法错误,意外的“索引”(T_STRING),预期为“,”或“;” in /home/hj016/public_html/SKSSTW/index1.php on line 102 在第102行的/home/hj016/public_html/SKSSTW/index1.php中

<?php
$sqlCommand = "SELECT id, linklabel FROM pages "; 
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); 
while($row = mysqli_fetch_array($query )) 
{    
echo "<li><a href="index.php?pid=".$row['linklabel'].>".$row['linklabel']."</a></li>";     
}
?>

Any help is appreciated. 任何帮助表示赞赏。

Change 更改

echo "<li><a href="index.php?pid=".$row['linklabel'].>".$row['linklabel']."</a></li>"; 

to

echo '<li><a href="index.php?pid='.$row['linklabel'].'">'.$row['linklabel'].'</a></li>'; 

You have a problem with double quotes, you are closing the echo string because you are not escaping them. 您对双引号有问题,因为没有转义,所以您正在关闭echo字符串。

I recommend you to use simple strings for the echo function: 我建议您将简单的字符串用于echo函数:

echo '<li><a href="index.php?pid="'.$row['linklabel'].'>"'.$row['linklabel'].'"</a></li>';     

If you are using double quotes, you can also use { } combined with the escaping tag \\ : 如果使用双引号,则也可以将{ }与转义标记\\结合使用:

echo "<li><a href=\"index.php?pid=\"{$row['linklabel']}\">{$row['linklabel']}</a></li>';     

Another escaping option opening and closing tags would be: 另一个转义选项的打开和关闭标签是:

echo "<li><a href=\"index.php?pid=".$row['linklabel']."\">".$row['linklabel']."</a></li>";     

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM