WordPress.org

Ready to get started?Download WordPress

Plugin Directory

dbview

Presents the results of a database query in a table. The query can be saved as a view which can then be embedded in any post using a shortcode. Views

Is it possible to pass arguments from a dbview embedded on a public facing page to an SQL statement?

A Yes. Use arg1 and arg2 to pass the arguments.

For example, to embed the results of this query:

select * from cities where country=%s and population > %d

use:

[dbview name='world cities in country' sort=city 
 order=asc pagesize=10 arg1='United States' arg2=5000000]

How do I load a second table from a link in the first table?

By using a link

<a href="?action=dbview&verb=autoLoad&name=NameOfView">my link</a>

An easier way is to insert a PHP snippet in a column in the first table:

return DBView::link($value, "name-of-dbview", optional-arg1, optional-arg2);

The loaded table replaces the existing table.

How do I pass the ID of the current user to a query relating to that user?

By invoking some PHP using another plugin such as 'Post Snippets' to load dbview and pass the appropriate argument.

For example to get the current user and display a table that shows that users information.

$u=wp_get_current_user(); 
echo do_shortcode("[dbview  name='show user' arg1=$u->ID]");

The corresponding SQL stored in 'show user' is:

select ID, user_login, user_email, user_registered, user_status 
 from wp_users where ID=%d

How can i show images in a table column and make them clickable links?

Assuming the image URL and the link URL are in separate columns in the table, it's necessary to concatenate the two URLs so as to not create an extra column in the view that is not wanted.

For example this SQL concatenates two URLs:

select id, concat('https://www.google.co.uk/images/srpr/logo11w.png',
',','http://www.google.com') as link from wp_posts limit 2

And this PHP snippet extracts the two URLs from the single column 'link':

$a = explode(",",$value);
return "<a href='".$a[1]."'><img src='".$a[0]."' /></a>";

Original discussion

Why are there no visible ascending or descending tabs on the column headers on the public facing pages?

Include the file (or the contents of) dbview.css into your theme.

I need to use a column from my SQL query in my PHP snippet, how can i prevent the column from appearing in the table?

At present, there is no way to hide columns.

Why are changes to the 'public' setting of a view not immediately effective?

Because the properties of each dbview are stored in the wp_options table which is cached for each session.

Requires: 3.0.1 or higher
Compatible up to: 3.9.1
Last Updated: 2014-6-6
Downloads: 3,095

Ratings

2 stars
2.5 out of 5 stars

Support

3 of 5 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1 50,2,1 100,1,1