[SOLVED] select element rowid from an article

Hello,
I have created a list of people and another list of events, and a third table that takes the name, address and event details from both tables.

now I need to generate a report from the third table with a custom text in a joomla article like this:

the person {fabrik view=element list=29 rowid=1 element=thirdtable___namesurname}, from {fabrik view=element list=29 rowid=1 element=thirdtable___address} attended this event: {fabrik view=element list=29 rowid=1 element=thirdtable___events} blah blah.

Is there any way that I can select in the article (maybe from a dropdown list) the rowid? in the third list I have created for each person the record of events, but how can I select in the article which record/rowid I want it to show?

Thank you
 
If I understand you correctly, I see a possiblity:
  • Create a form with a Dbase join to the third table as a dropdown list like you want.
  • Put the form in the Article at the top of the page (or wherever) - you could use the Fabrik module plugin to get it out of the way of the article if you want.
  • Then set up a redirect plugin in the form settings to redirect to the same article, but to append ?id=x (that is the id value selected by the user in the dropdown)
  • You'll need a plugin like Sourcerer to be able to run some php code in the Article. Get sourcerer - there is a free version and it usually plays nice with Fabrik.
  • then Write your article as you want it in the article and fill in the data you want with calls to the database using sourcerer tags surrounding the php code AND use $_GET['id']; to pull the value selected in dropdown from the URL and use it to find the data in the third table via a php select request like ie. select namesurname from thirdtable where id = x;
I don't know your skill level, but this would allow you to choose your record from a dropdown list. Press submit and it will refresh the page with the id selected in the url. Your php code embeded in text of the article will pull the desired data from the table. With each new select and submit, the newly selected id will populate new data in article text.
Good luck,
Jeremy
 
I'm a beginner with PHP, but by searching forums I managed to get several simple (but effective) solutions with only fabrik modules.
I will try to find some examples for the use of the Sourcerer, and hopefully I can implement it.
I was kind of hoping there was an easier non-PHP way of doing this.
 
Hi Vladimir,

I'll walk you through it, in detail - I'm sure this will be useful to others too. The new wiki has a lot of good info but it's a work in progress.

For anyone stumbling on this in the forum, these steps outline, step by step how to:
CREATE A DROPDOWN IN A MODULE TO DISPLAY A JOOMLA ARTICLE POPULATED BY THE SELECTED DATABASE RECORD

1. Create a small single purpose Form in Fabrik. Fabrik->Forms Choose New (Orange Plus icon). Name and save it. This should create a Form, Group and 2 elements. (Note: this will not create a table for the form and so will not store each submission of this form. To do that, create a Table instead of a Form, the Table will create the form for you.)
2. You need to add 1 more element of Plug-in type=databasejoin.
For the element: Render Join as Dropdown.
Under the Heading Data, Table=[choose the table you want to display],
Value[choose an element from the table, usually id, but you need a unique identifier for the record you will select in the dropdown],
Label=[choose the element you want that is human friendly to select the desired record],
Or Concat label=[If you need to give more info in Label to select, if say you have users occurring more than once at multiple venues, then you will want to have a Label that displays the Username & Venue.
As an example, you might enter:
Code:
{thistable}.mbr_name,' - ',{thistable}.venue
Joins where and/or order by statement (SQL) is a simple sql where statement like:
Code:
WHERE {thistable}.active_status = '1' ORDER BY {thistable}.venue DESC
This statement would only show records with an active status of 1 and the dropdown would display in groups by venue and descending.
Generally, you can leave the rest of the settings as they are - read the Label tips and experiment if needed to see how they work.
3. In your Joomla Extensions, Module Manager you will find a Module called Fabrik Form Module. Open this and in the Advanced options on the right, Choose your newly created form. Set Row id=0. Choose a Form Template from the list - start with default. I don't think Ajaxify will matter here, but let's say Yes. In the Menu, Assignment section, select the menu item(s) you want this form to display on. Depending on your Template, you'll need to choose a Position for your form to display - select a position and visit the page you've assigned to see that it is appearing and is in the location you want. (Make sure the Module is enabled)
4. Next you need to create a redirect plugin, go to Fabrik->Forms and select your newly created form. Choose the Plug-ins Tab and press Add. --do--=redirect, in=Front end, On=New. Under Jump page, enter the link you want. That is, go to the Article page you want and copy from the URL but leave off the domain name like:
Code:
/myarticlepageurl
//Whatever the URL of the page you want to land on is, enter it here
With the Append jump url with data=yes. Under Module/content plug-in redirect options set Conent Reset=Yes, Content Redirect=Same Page. leave the rest blank.
Alternatively, choose no for Append jump url with data, and you can try to set the appended data yourself in the Jump Page box with something like:
Code:
/myarticlepageurl?venueforuser={___mydbasejoinelementname_raw}
//Adding _raw will fills in the unique id, leaving off _raw fills in the Label
This way, you can make the label whatever you want instead of what Fabrik generates.
5. Test the form on your article page. If it's working it should reload the page with ?venueforuser=x or it will use your elementname and the value after the ? (or if appended data already exists you may need or it will use & instead of the ? to append in the URL.
6. Install Sourcerer from NoNumber. Go to Joomla's Extensions->Plug-ins in the filter box, type sourcerer.Open the Sourcerer Plugin and set Basic Options to a unique tag like mysourcerertag. Leave the rest of the options alone.
7. In your article you will input your article like this:
Code:
OPTION 1:
${mysourcerertag}<?php $query = "SELECT exactelementname FROM exacttablename WHERE id = $_GET['venueforuser']";$database->setQuery($query);$result = $database->loadResult();echo $result;?>{/mysourcerertag} Monthly Membership including 1 Free Trial Month.  First Payment one month AFTER Activation via Paypal:
This seems a bit complicated but it's really just cut and paste: You only need to set the exactelementname, exacttablename, and venueforuser parts of this. These three pieces select the column, table and record respectively, letting you pull any value you want from the database. The code parts are just telling PHP and MySql what you want and what to do with it (echo which will display it for you.)
Note: In this case, the $_GET['venueforuser'] bit of code is pulling the value supplied in the URL ie. /featured-vehicles?venueforuser={___mydbasejoinelementname_raw} will become /featured-vehicles?venueforuser=x and the $_GET command will pull the x value.
Each time you select a new record from the dropdown, a new x value will show in the URL and this will cause the php code to pull the values for elements in the new record.

This is a long bit of text because I've explained nearly every step required. Just follow the steps and this should work nicely.
If it's not working - re-read the steps closely. You may have missed something.
(Note that I haven't done this myself - I'm just writing out the steps I would take. I may have missed something.)
Good Luck,
-J
 
Thank you very much J!

I'll try to see if it's working and I'll post back. In any case I really appreciate your help.

Best wishes,
Vladimir
 
Hello J,
after almost a year I finally found time to try out your solution, and so far it's working until I put {mysourcerertag} in an article. Although it will print out a simple echo command, whenever I save it with a query like the one you specified (but with my parameters), the article becomes a blank page, that is there is nothing in the browser (not even the menu) I even used the fixed value for the id, just to see if the element name is wrong, like this:
PHP:
{mysourcerertag}
<?php
$query = "SELECT 'jmbg' FROM 'dip_datipersonali' WHERE 'id'='83';
$database->setQuery($query);
$result = $database->loadResult();
echo $result;
?>
{/mysourcerertag}

The 'Append jump' shows the following after selecting a value from the drop down list:
http://localhost/index.php/test1?test_form1___id=12&test_form1___nome_cognome[value]=7

so basically the $_GET is 'test_form1___nome_cognome' and not 'test_form1___nome_cognome[value]'?
 
Small update,
I tried to echo only the $_GET,
PHP:
{mysourcerertag}
<?php
$userid = $_GET['test_form1___nome_cognome'];
/* $query = "(SELECT jmbg FROM dip_datipersonali WHERE id = '{$userid}')";
$database->setQuery($query);
$result = $database->loadResult();
echo $result;*/
echo $userid;
?>
{/mysourcerertag}

and (only) when I put in 'test_form1___nome_cognome' the result is simply "Array" without the quotes.

[UPDATE - Array part]
in the redirect page, I selected not to append and imputed the linklike this
index.php?option=com_content&view=article&id=3&venueforuser={nome_cognome_raw}
so it's not "?" but "&"
Now it is outputing the venueforuser correctly in the page, but I still can't get the query to work

[UPDATE - query]
I just can't get it to work. I also tried the PHP code from the common PHP examples of the fabrik website:
PHP:
<?php
 
$userid = $_GET['venueforuser'];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
 
$query
    ->select('jmbg')
    ->from('dip_datipersonali')
    ->where('id = '.$db->quote('$userid'));
 
$db->setQuery($query);
$fieldA = $db->loadResult();
var_dump ($fieldA);
 
?>
I used var_dump, and the result ($fieldA) is NULL, $userid is correctly recognized.
I really don't know what else to do, any suggestion is appreciated.
 
I think I found the problem, my table is on a database connection different then the one on Joomla, so I tried:
PHP:
$db = FabrikWorker::getDbo(false, 2);
 
$query = "show tables";
$database->setQuery($query);
$result = $database->loadResult();
echo $result;
just to see if it is even connecting to the database and the result is: zn9op_ak_profiles
Even if I change to connection to a different tadabase getDbo(false, 1)
So the only problem it seems is that can't connect to the database

[UPDATE]
when I try FabrikWorker::getDbo(); it simply returns "2" on the placeholder, so I am guessing it's actually using the right connection.
 
I did it! I found the mistake, and now everything's working :)
boy, am I happy right now :D
here's the code in case anyone should need it:
PHP:
<?php
 
$userid = $_GET['venueforuser'];
$db = FabrikWorker::getDbo();
$query = "SELECT jmbg FROM dip_datipersonali WHERE id = $userid";
$db->setQuery($query);
$result = $db->loadResult();
echo $result;
 
?>

Jeremy, thank you very very much for all your hard work and detailed explanations, I couldn't have done it without you.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top