Passing user variable to a php file

A multipurpose module, plugin and component

Passing user variable to a php file

New postby [email protected] » Sat Nov 27, 2010 4:24 am

Hi all,

First of all I'd like to say that Jumi is great, I just installed it today and it's awesome. Thumbs up to the developer.

Now I have a question, hopefully someone knows how to do this.
So I'm trying to get some content displayed from a MySQL DB in a joomla article that's only visible to registered users and the content is specific to each user.
So this is what I have now, I have an article with some text and {jumi [output.php]}, so the php file gets the whole db and displays it. The DB is simple, email is the key and then there is some additional info pertaining to the user. So for now I display the whole DB to every user.

So my question is how to pass a variable from joomla that contains the user email so I can only display the proper row that pertains to the user that's currently logged on.

This is the php code I have so far.
$db_host = 'xxx';
$db_user = 'xxx';
$db_pwd = 'xxx';

$database = 'xxx';
$table = 'xxx';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die("Query to show fields from table failed");

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
echo "<tr>";

// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";

echo "</tr>\n";
[email protected]
Posts: 1
Joined: Sat Nov 27, 2010 4:11 am

Re: Passing user variable to a php file

New postby Edvard » Sun Nov 28, 2010 1:26 pm


You can use Joomla API to access all the objects. To get the user you can use this:

Code: Select all
$user =& JFactory::getUser();

You can find more about JUser object on

Edvard Ananyan - 2GLux Team

Please post a review at the Joomla Extensions Directory. It is very important for us!
Site Admin
Posts: 1836
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

Return to Jumi

Who is online

Users browsing this forum: No registered users and 5 guests