1

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.

Vivek Singh
  • 2,453
  • 1
  • 14
  • 27
Manisha Singh Sanoo
  • 919
  • 1
  • 13
  • 42

2 Answers2

2

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>'
);
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
1

You should use something like this in Moodle

$editurl = new moodle_url('/pluginfolder/pluginname/edit.php', array('id' => $id));
$editlink = html_writer::link($url, get_string('edit'));
$table->data[] = array('CSE1010', 'Intro To IT', 'Bsc Acc, Mgt', $editlink);

$id is the id of the record you want to edit.

Russell England
  • 9,436
  • 1
  • 27
  • 41