How do I put a query on the front page?

How do I put a query on the front page?

J m發表於
Number of replies: 4

If there's a beginner link to help, sorry, but all I want to do is put the results of a query on the front page.

I am able to do simple things like echo $USER->id, but what if I want to do something very simple like query with that userid?  All I need is a simple example like select the users information, just so I can see how it fits together.  A hello world from the database.  I started to just add my own mysql connection strings, but that didn't make sense, wanted to do it right.

Any hand holding is appreciated.  Thank you.

評比平均分數: -
In reply to J m

Re: How do I put a query on the front page?

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
Try this for a start (put it in the Moodle home directory):

<?php require('config.php'); require_login(); print_object($USER); /// global object that is always available for logged in users $user = get_record('user', $USER->id); /// Getting a record from a db table if ($user) { print_object($user); /// what the plain record looks like } else { error('No user found! This should never happen.'); } ?>
In reply to Martin Dougiamas

Re: How do I put a query on the front page?

Hassani Hachim發表於
hello martin,
I tried this code and got an error. Then i changed this line $user = get_record('user', $USER->id); to $user = get_record('user', 'id',$USER->id);
Now it works.
Actually i'm interested in way to make my own php page.
A couple of days ago, i wrote my first modules and blocks but i don't know how to do if i want to call an existing block (eg online users, calender block). I've tried several methods like $mybloc = block_instance('block_calender')..., but it doesn't work. Now i'm on page 7 of this general developer forum but i can't find a solution, maybe you could help me (if you have a little time, i would really apreciate)