Search code examples
phphrefmoodle

Adding a link in an array in PHP using href


I am developing a plugin for Moodle and I have to add data to the table I created.

This is the code:

<?php

$table = new html_table();
$table->head = array('ID', 'Name', 'Programme', 'Edit', 'Delete');
$table->data[] = array('CSE1010', 'Intro To IT', 'Bsc Acc, Mgt', ?> <a href="edit.php"><u>Edit</u></a> <?php);
$table->data[] = array();
echo html_writer::table($table);

echo "... Your PHP data handling code";

echo $OUTPUT->footer();

?>

I am having problems to add a link inside the table.
This part of the code is giving me an error:

$table->data[] = array('CSE1010', 'Intro To IT', 'Bsc Acc, Mgt', ?> 
<a href="edit.php"><u>Edit</u></a> <?php);

The error message is:

Parse error: syntax error, unexpected '?>', expecting ')' in C:\MoodleWindowsInstaller-latest\moodleFile\server\moodle\local\try\index.php on line 29

I can understand that the way i wrote it is incorrect. Can someone help me to write it the correct way? Thanks.


Solution

  • No need of the PHP tags. Try with -

    $table->data[] = array(
          'CSE1010', 
          'Intro To IT', 
          'Bsc Acc, Mgt', 
          '<a href="edit.php"><u>Edit</u></a>'
    );