尝试为按钮分配主键值时出错?

50few1ms  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(287)

这个问题在这里已经有答案了

php解析/语法错误;以及如何解决这些问题(18个答案)
两年前关门了。

  • 从数据库(phpmyadmin)打印表中的数据

“查看更多”按钮需要具有每行的主键值,以便为每个事件显示不同的信息。
代码:

<?php
try{
// Run a SQL query
  $sqlstr = "SELECT * FROM events";
  $rows=$db->query($sqlstr);
//loop through all the returned records and display them in a table
  foreach ($rows as $row) {
    echo  "<tr><td >" . $row['eventCategory'] . "</td><td >" . $row['eventName'] . "</td><td >" . $row['time']. "</td><td >" . $row['description']  . "</td><td >" . "<a href='viewmore.php?event_id= $row['event_id']' id='viewbtn' name='viewbtn'>view more</a>"."</td></tr >" ;

  }

  echo "</table> <br>";
} catch (PDOException $ex){
  //this catches the exception when the query is thrown
  echo "Sorry, a database error occurred when querying the vehicle records. Please try again.<br> ";
  echo "Error details:". $ex->getMessage();
}

?>

当我运行它时,我得到这个错误。。
分析错误:语法错误,意外的“”(t\u封装了\u和\u空格),需要“-”或标识符(t\u字符串)或变量(t\u变量)或数字(t\u num\u字符串)
错误就在这一行

echo  "<tr><td >" . $row['eventCategory'] . "</td><td >" . $row['eventName'] . "</td><td >" . $row['time']. "</td><td >" . $row['description']  . "</td><td >" . "<a href='viewmore.php?event_id= $row['event_id']' id='viewbtn' name='viewbtn'>view more</a>"."</td></tr >" ;
uoifb46i

uoifb46i1#

在$row['event\u id']附近添加“”可以正常工作

<?php
try{
// Run a SQL query
  $sqlstr = "SELECT * FROM events";
  $rows=$db->query($sqlstr);
//loop through all the returned records and display them in a table
  foreach ($rows as $row) {
    echo  "<tr><td >'".$row['eventCategory']."'</td><td >'".$row['eventName']."'</td><td >'".$row['time']."'</td><td >'".$row['description']."'</td><td >" . "<a href='viewmore.php?event_id= ".$row['event_id']."' id='viewbtn' name='viewbtn'>view more</a>"."</td></tr >" ;

  }

  echo "</table> <br>";
} catch (PDOException $ex){
  //this catches the exception when the query is thrown
  echo "Sorry, a database error occurred when querying the vehicle records. Please try again.<br> ";
  echo "Error details:". $ex->getMessage();
}

?>

相关问题