Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » How can this work ??
How can this work ??
How can this work ??
hello, my question is :
I have a table which has for a specific user 3 entries. Each record has a field called menumodule, and in this field i have stored the module id.
Now i would like the metamod module to run the query for the user and display the modules based on the field menumodule.
I am sorry but i am not an php expert.
Thank you for your time.
Alexander
Re: How can this work ??
Hi Alexander,
Try this, replacing the table and column names as appropriate:
if ($user->id == 0) return; // bypass if not logged in
// replace MYDBTABLE with the name of the database table
// replace USERID with the name of the column that has the user id in it
$sql = "select menumodule from MYDBTABLE where USERID = " . (int)$user->id;
$db->setQuery($sql);
$result = $db->loadResult();
if ($result > 0) return $result;
Re: How can this work ??
Hello Stephen,
1st of all i would like to congratulate you for these awsome extensions. I have already purchased Chameleon and I am going to purchase metamod pro too if it does what i am trying to fix.
The code you gave me works but it only displays 1 record. I will explain the idea.
For example:
I have no1 customer that has 1 vehicle ( fiat 500 ) and i have customer no2 that has 3 vehicles ( fiat 500, lancia ypsilon, alfa romeo gulietta ).
I have created 3 menu modules and each module has the id's ( 20, 21, 22 )
I have a table which has 1 record for customer no1 and 3 records for customer no2 ( every record has an column called menumodule, and the id of the module i want to display is entered there ).
What i would like is, when i select the records for customer no2, to be able to display the 3 menus.
But if a customer has 2 vehicles as same model example: 2 records fiat 500, to display the Fiat menu which its id is 20 once.
Thank you again for your time, and Thanks for these extensions !!!!
Best Regards
Alexander
Re: How can this work ??
Yes, that's a nice simple change to the recipe:
if ($user->id == 0) return; // bypass if not logged in
// replace MYDBTABLE with the name of the database table
// replace USERID with the name of the column that has the user id in it
$sql = "select DISTINCT menumodule from MYDBTABLE where USERID = " . (int)$user->id;
$db->setQuery($sql);
$result = $db->loadResultArray();
return $result;
The DISTINCT keyword ensures you don't get duplicates. The loadResultArray() method gets all the results and puts them into an array. MetaMod is happy to accept an array as the "return" value, and uses the values as module ids.
I think that should work...
Best regards,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » How can this work ??
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7627
- Newest User:
- rudys68879
- Members Online:
- 0
- Guests Online:
- 177
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked