1

*the data from the table is printed from the database(phpmyadmin)

The 'view more' button needs to have the primary key value for each row so that it shows different information for each event.

code:

<?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();
}

?>

When I run it, I get this error..

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in

The error is on this line

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 >" ;

1 Answers1

0

Add "" around $row['event_id'] works fine

<?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();
}

?>
Alan
  • 386
  • 1
  • 3
  • 17