Using Database Query (DBQ) in Joomla!

How To Install DBQ Component in Joomla!

Download DBQ

  1. Download Database Query for Joomla! 1.0 here.

Install DBQ

  1. Login into the administration area and go to Installers > Component from the menu.
  2. Use the “Choose…” button under Upload Package File to select the file you just had downloaded. Then click on Upload File & Install.
  3. If installation is successful, a “Upload component – success” page will appear.

Connect DBQ to your database

  1. In the administration area, go to Component > DBQ Manager > Databases.
  2. Click New to specify new database connection.
  3. Select the correct Driver and Type according to your database. Enter “localhost” as the Hostname if you are using a local web server. Schemaname is the name of your database in the web server. Fill in the right Username and Password. Click Save when you are done.
    database connection for DBQ

Create Category

  1. In the administration area, go to Component > DBQ Manager > Categories.
  2. Click New to create a new category and fill in the Category Name, Category Title, and Description. Click Save when you are done.

Basic Search Query

Step One: Create the Query.

  1. In the administration area, go to Component > DBQ Manager > Queries.
  2. Click New to create a new query.
  3. Type in your SQL statement. For this exercise, I use the following SQL:

    SELECT
    pel_name    AS $<Pelajar_Name>,
    pel_no_matriks  AS $<Pelajar_No_Matriks>,
    pel_sesi    AS $<Pelajar_Sesi>,
    pel_id      AS $<Pelajar_View_Link>
    FROM tbl_pelajar
    WHERE pel_id != 0

  4. Fill in all the other fields in the Configuration tab as illustrated below:
    create query with DBQ
  5. On the Attributes tab, set Published to “Yes”.
  6. On the Parameters tab, set Order Variables As Found In Query to “Yes”.
  7. Click Save. The query will be listed in DBQ Manager > Queries. You can also view the query on the front end at http://localhost/joomla/index.php?option=com_dbquery

Step Two: Parse the Query.

  1. Tick the checkbox next to the query name, and click the Parse button.
  2. Check that the type of each variable is set to “Field Variable”

Step Three: Configure the Variables.

  1. Set all variables to active

Display Your Query

  1. Now that your query is ready, you can assign it to a menu in Joomla!. In the administration area, go to Menu > mainmenu.
  2. Click New. Select Components.
  3. Specify the name of your menu. Select DBQ Manager from Component and click Apply.
  4. Under parameters, enter the DBQ Query ID for your created query (you can check it on DBQ Manager > Queries) and click Save.
  5. You will see your newly created menu on your Joomla! home page.

Advanced Search Query

  1. In the administration area, go to Component > DBQ Manager > Queries.
  2. Tick our previous query and click the Copy button.
  3. Click on the query name to modify it using the following SQL:

  4. SELECT
    pel_name    AS $<Pelajar_Name>,
    pel_no_matriks  AS $<Pelajar_No_Matriks>,
    pel_sesi    AS $<Pelajar_Sesi>,
    pel_id      AS $<Pelajar_View_Link>
    FROM tbl_pelajar
    WHERE pel_id != 0
    $[PEL_SEARCH_NAME:  AND pel_name LIKE '%${pel_search_name}%'  ]
    $[PEL_SEARCH_NO_MATRIKS:  AND pel_no_matriks = '{pel_search_no_matriks}'  ]
    $[PEL_SEARCH_SESI:  AND pel_sesi = '${pel_search_sesi}'  ]

  5. Parse the query. Set :
    • PEL_SEARCH_NAME,  PEL_SEARCH_SESI and PEL_SEARCH_NO_MATRIKS to type “Statement Variable”.
    • pel_search_name to type “Keyword Variable”
    • pel_no_matriks and pel_search_sesi to type “Query Result Variable”
  6. Configure the variables:
    • Edit each statement variable to “Not Required”
    • For “Keyword Variable”, use “Text Box”
    • For “Query Result Variable”, use the “Drop Down List” input
    • Set SQL query for pel_no_matriks in the Parameters tab: SELECT pel_no_matriks AS value, pel_no_matriks AS label FROM tbl_pelajar ORDER BY pel_no_matriks
    • Set SQL query for pel_sesi in the Parameters tab: SELECT pel_sesi AS value, pel_sesi AS label FROM tbl_pelajar ORDER BY pel_sesi
    • Set the Data Source to “SQL Query”
  7. Test the query.

Basic View Query

This query will let the user view a specifc record in the table.  Our third query resembles the other two queries except that it displays additional felds and accepts only a single input, the record ID.

  1. Create the query:

  2. SELECT
    p.pel_no_matriks  AS $<Pelajar_No_Matriks>,
    p.pel_name    AS $<Pelajar_Name>,
    j.jab_name    AS $<Jabatan_Name>,
    p.pel_sesi    AS $<Pelajar_Sesi>,
    p.pel_alamat  AS $<Pelajar_Alamat>,
    p.pel_jantina AS $<Pelajar_Jantina>,
    p.pel_ic      AS $<Pelajar_Ic>,
    p.pel_no_tel  AS $<Pelajar_No_Tel>,
    p.pel_id      AS $<Pelajar_View_Link>FROM tbl_pelajar p, tbl_jabatan jWHERE p.pel_id = ${pelajar_id} AND p.jab_id = j.jab_id

  3. In Attributes tab, set Rotate Results to “Yes”
  4. Parse the query:
    • pel_id as “Keyword Variable”
    • others as “Field Variables”
  5. Configure variables: pel_id to “Required”
  6. Test query.

Linking Queries Together

Earlier, we created the Pelajar_View_Link field variable which presented the record id for the selected record.  We will now modify this variable to create a link to the View query

  1. Configure the variable, Pelajar_View_Link:
    • In Parameters tab, set Enable Next Query to “Yes”
    • Set Next Query ID, enter the query ID
    • Set Next Query Task to “Execute Query”
    • Set Target Variable to pelajar_id
    • In Special tab, Enter: $replacement = ‘view’;
  2. Hide the view query using the query parameter “Hide On Select Screen”
  3. Test the query.

2 Comments »

  1. ketek said

    useless without pix

  2. Nitin said

    I want to run a query based on user name…. actually i have one table for each user in database and i want to display the contents of the table of the logged in user. How do i do that?? any ideas!!!

RSS feed for comments on this post · TrackBack URI

Leave a Comment