Displaying Query Results as a Table
Ответ
Task
We need to display list of the results of a query to Joomla! database as a table.
Solution
Set the DW Anything module settings as follows.
Setting | Value | Description |
---|---|---|
SQL Query |
SELECT * FROM `#__users` |
Enter SQL query to retreive the list of user names from Joomla! users table. Note that you can use standard Joomla! '#_' prefix for database table names |
Header HTML |
<table> <thead> <tr> <th>Name</th> <th>User Name</th> </tr> </thead> <tbody> |
Enter HTML code to display before the resulting list of data rows. Table opening tag and column headers go here. Add column headers as required |
Template |
<tr> <td>{name}</td> <td>{username}</td> </tr> |
Enter HTML code to display each data row returned by SQL query. To insert data field, type it's name enclosed within curly barckets ({}). Add fields for all data columns you want to display here |
Footer HTML |
</tbody> </table> |
Enter HTML code to display after the resulting list of data rows. Place table closing HTML tags here |
Result
Name | User Name |
---|---|
john | John Smith |
mary | Mary Brown |
Комментарии
To distinguish between odd and even rows, use the counter variable in your MySQL query as follows:
SELECT @parity := IF(@parity, 0, 1) AS `parity` FROM `#__content`, (SELECT @parity:=0) AS `a`
SELECT DATE_FORMAT( date_time, '%M %d, %Y' ) AS date, TIME_FORMAT( date_time, '%h:%i %p' ) AS time, name
FROM jos_chronoforms _photo_director y
ORDER BY date ASC , time ASC
How would I get odd/even rows and use in my template?
Thanks
SELECT DATE_FORMAT( date_time, '%M %d, %Y' ) AS date, TIME_FORMAT( date_time, '%h:%i %p' ) AS time, name, @parity := IF(@parity, 0, 1) AS `parity`
FROM jos_chronoforms _photo_director y, (SELECT @parity:=0) AS `a`
ORDER BY date ASC , time ASC
Template: <tr class="row{parity}">...</tr>
Odd rows will get the "row1" class, even rows - "row0" class.
I rode answer abowe but i don't understand. I used query;
---------------------------
SELECT DATE_FORMAT( date_time, '%M %d, %Y' ) AS date, TIME_FORMAT( date_time, '%h:%i %p' ) AS time, name, @parity := IF(@parity, 0, 1) AS `parity`
FROM jos_chronoforms _photo_director y, (SELECT @parity:=0) AS `a`
ORDER BY date ASC , time ASC
Template: ...
Odd rows will get the "row1" class, even rows - "row0" class.
----------------------------------
but there isn't any change
please help me. I want to do
first row blue
second row white
third row blue
forth row white
....... etc
To see any changes, you'll need to add CSS styling as well.
The styles you add could be something like this:
.row1 {
background-colo r: #B6F3F9;
}
.row0 {
background-colo r: #FFFFFF;
}
For example, I want to display registered info in a table format, such as:
image, Name, phone, address, webURL, etc...
some users do not want their info displayed...is there some sort of control for that?
I'm creating a website for a non-profit org, but am having problems displaying user info; I have AEC extension for free & paid membership, I also use Jomsocial & link Jomsocial profile & registration together...so there are quite a number of fields, ie. user images, name address, phone, website, professional specialty, paid/not paid status, groups, etc...
If this extension is capable of displaying any fields in the mySQL, can it display the above info...assuming that Jomsocial also uses mySQL?
Thank you & God bless
Yes, you can display data from JomSocial. You'll need to select it from corresponding JomSocial tables in your MySQL query.
I don't realy know if JomSocial allows you to add custom fields to user profile, but the chance is it does (like, say Community Builder). If so, you should add the check box control to profile, so user could check it to state if he/she wants to display user info. The user choice then should be stored in JomSocial database table(s), so you could use it in the WHERE clause of your MySQL query to select only users who agreed to show their info.
Just add the formatted date to your SELECT fields list, e.g.
SELECT *, DATE_FORMAT(`da te_field`, '%W %M %Y') AS `date_formatted ` FROM `jos_your_table _name`
Цитата: My only problem is that all entries in the db with apostrophes are being escaped by a backslash. For example
O'Daniel's Flower Shop shows up in the table as
O\'Daniel\'s Flower Shop
Any help would be appreciated
For usage example, see How do I display line breaks? article.
First of all, i have to say thanks for the great job.
For me, i ld like to ask how can display image from my restore db table?
Thanks in advance!
Thank you.
Could you please be more specific about your question? What is restore DB table? How does your image stored in it?
First of great job on this module, but how do i display my query results as marquee text in one line taking the example above removing header and footer html and replacing template with "{name}-{userna me}" its displaying each result in a separate row how do i get it to display in one row
my code:
SQL Query : SELECT * FROM `#__users`
Template: {name}-{username}
with the above code results are diplaying in separate rows how do i get them to dipaly in one row?
To display the marquee text in one row, please try putting the marquee opening and closing HTML tags into the Header and Footer sections of DW Anything module parameters.
I'm not sure I've got your question right. Do you want to display your database data as a table with a limited set of columns?
Congratulations for the excellent and simple extension!
I just made the table with the query, it´s working fine.
I need to create two buttons in the same line: DELETE REGISTER and EDIT REGISTER.
The DELETE button could make a DELETE SQL command using the ID of the register.
The EDIT button could carry some variable through HTTP and link with a CHRONOFORMS form so the entire field could be edited.
Thanks in advance!
Cheers
Lucas
Thanks.
You can place the HTML forms containing the DELETE and EDIT buttons within each row of your table using DW Anything Template.
Still, you'll need to point them to some server-side script which does the processing stuff for you. DW Anything won't do the processing job.
I am using your module to display a db table. It works very well thank you.
I need to change the color of a row depending on a field. where can I do such a thing? I see what you have done with the alternating rows but I dont believe I can use that.
Fatal error: Class 'JFile' not found in C:\xampp\htdocs \blwgzone\modul es\mod_dwanythi ng\helper.php on line 25
SELECT *, DATE_FORMAT(`Or der_Date`, '%DD %MM %YY') ,DATE_FORMAT(`A fleverings_Dato `, '%D %M %Y') FROM `Orders`
ORDER BY Order_Id DESC
LIMIT 0 , 10;
E.g.:
SELECT *, IF(`approved`, 'background-col or: green', 'background-col or: red') AS `formatting`, etc...
Then, you can get the {formatting} column value and use it in your Template:
<tr style="{formatt ing}">
<td>{name}</td>
<td>{username}</td>
</tr>
Can i add a page navigation and a button for data export in csv format?
SELECT * FROM #__table_name ORDER BY auto_incremente d_id DESC LIMIT 1
where auto_incremente d_id is most commonly the id column of your table.
{Name}
{Item}
Unfortunately, no HTML allowed in user comments, so I cannot see your example.
Have you figured out how to complete your task yet?
ColA
Unfortunately, no HTML allowed in user comments, so I cannot see your example.
Generally, you can use inline CSS in your templates.
Fatal error: Class 'JFile' not found in path/helper.php on line 25
??
Please keep track of version updates.
RSS лента комментариев этой записи