English 中文(简体)
PHP Function Help
原标题:
  • 时间:2010-02-21 12:08:00
  •  标签:
  • php
  • moodle

I ve written this piece of code, which outputs the profile_display_fields for the $USER:

$appearance = profile_display_fields($USER->id);
        if (empty($appearance)) {
            //Do nothing
        } else {
            foreach ($appearance as $c) {
            $custom .=  <a href=  .$CFG->wwwroot. /course/view.php?id= .$c->id.  > .$c->fullname. </a> ;
            }
        }

Here is the function I m using:

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

What I m looking to do is try some var_dumps to output the correct data.

However can anyone help me identify the variables?

问题回答

In your function you are not returning any value but above that in your code, you have assigned a variable to this function:

$appearance = profile_display_fields($USER->id);

You need to return some variable/data from the function and that is the one to be var dumped.

I suppose you are using the print_row to print the data, not returning the response to be used out of the function.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签