0

I realise this is a bit vague but hoping someone might be able to point me in the right direction.

This is the error: Fatal error: Call to undefined function print_row() on line 418

Cause by this line:

**$something = profile_display_fields($css->id);**

In this code:

$customcss = get_records_select('user_info_field', '', 'sortorder ASC');

foreach ($customcss as $css) {
  if ($css->name == 'usercss') {
   $something = profile_display_fields($css->id);
  }
}

Here is line 418:

print_row(s($formfield->field->name.':'), $formfield->display_data());

And here is the whole function:

function profile_display_fields($userid) {
    global $CFG, $USER;

    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
        foreach ($categories as $category) {
            if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
                foreach ($fields as $field) {
                    require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
                    $newfield = 'profile_field_'.$field->datatype;
                    $formfield = new $newfield($field->id, $userid);
                    if ($formfield->is_visible() and !$formfield->is_empty()) {
                        print_row(s($formfield->field->name.':'), $formfield->display_data());
                    }
                }
            }
        }
    }
}
1
  • 7
    Where is print_row() defined? The error is because PHP can't find it. Commented Feb 21, 2010 at 18:09

3 Answers 3

2

The error is rightly pointed, i could not find the function print_row defined somewhere in your code. Make sure that you define that function, it looks like that function is present in some other file, try searching for this function in other files and include that file in your script and this error won't show up again.

Sign up to request clarification or add additional context in comments.

Comments

1

That looks like moodle's profile_display_fields() defined in user/profile/lib.php.

The print_rows() function is defined in user/view.php. Make sure this file is included prior to the call of profile_display_fields().

edit:

function print_row($left, $right) {
    echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";
}

That's the "original" definition of print_rows(). Define it somewhere in case you're using user/profile/lib.php but not view.php.

edit: I don't like it, but you can make a function definition conditional to avoid "fatal error: cannot re-declare function xyz"

if ( !function_exists('print_row') ) {
  function print_row($left, $right) {
    echo "\n<tr><td class=\"label c0\">$left</td><td class=\"info c1\">$right</td></tr>\n";
  }
}

4 Comments

Given this, is print_row(s a typo?
No, the code in the question seems to be a 1:1 copy from lib.php I just downloaded moodle-weekly-19 and it's the same. btw: it's print_row(s(...), ...), whatever function s() does; it's the first time I heard of "moodle" ;-)
Welcome to the world of Moodle lol Added the function and the code works!
The trouble is this function is already declared on some pages where I want to use my code and it screws up?
0

Your code fails with this error because:

  • print_row() is not a function part of the PHP Core
  • No PHP extension is defining print_row()
  • Your code hasn't defined a function called print_row() before the execution of that statement.

If print_row() is defined in an external file, make sure that this file is included before calling the function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.