e107help.org Q&A
0 like 0 dislike
I have created several plugins and got them to work in the admin-cp, I can add and edit data which is stored in the database.

What I want to do is: Use the data from the database on a page, for example: Let's say we have a database table for storing information about record labels, we can add and edit record labels from the admin-cp but we also have a page called Labels where we would like to display the information from the database in the current theme format.

I have looked all over the place and tried experimenting with files in the plugin folder but I have not managed to get it to work.

Can anyone help with this, or at least point me in the right direction please?
e107 version 2
in Plugins by (9 points) 2 5

No knowledge how to do this directly, but this seems to do what you try to achieve.

$sql = e107::getDb();

so here's some more if you like to do it yourself https://www.w3schools.com/php/php_mysql_select.asp.
and of course https://www.e107.org/developer-manual/classes-and-methods/database

And while using the above quote take a look how faqs plugin does it. (it uses db stored content)
If you have some software that can search in files for texts use the above quote (....getDb ) and you find a lot of possible methods. Maybe theres something that you could use and do not have to re-invent.

So nor real answer but hopefully it points in the right direction..

(Ehhh rewrite??  faqs plugin and use this as a new plugin called Labels? ...just some querky idea)

Thanks for your answers. What I did in the end was to create custom pages, (php files in the site root folder), that display the content that the plugin has generated.

This is read from the database and I was able to produce some basic pages which render nicely. However, they are basic pages and do not follow the theme template, in other words, there is no option to rate/share/comment on the pages.

This is now the biggest problem that I have and if anyone has any idea's/suggestions, please comment thanks.

Example php page.

$ns->tablerender("Axis Record Labels");

// Create connection
$conn = new mysqli($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

$sql = "SELECT * FROM `axis_record_labels`";
$result = $conn->query($sql);
$records = $result->num_rows;

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$imageurl = "{e_MEDIA_IMAGE}2019-04/white-lion-audio-profile-image.jpg";
$image = $tp->thumbUrl($imageurl);
echo "<div class='jumbotron'><hr class='my-4' /><img style='border-radius:3px;' src='{$image}' alt='{$row["label_name"]}' />  <span class=\"badge badge-primary\">{$row["label_name"]}</span><br /><br />";
$id = $row["id"];
$name = "<h1 class=\"badge badge-secondary\">Label Name: {$row["label_name"]}</h1>";
$description = "<strong>Record Label Description:</strong> {$row["description"]}<br /><br />";
$email = "<strong>Email address:</strong> <a href='mailto:{$row['email']}?subject=Email sent from The Axis Online website' title='Click to send email'>{$row['email']}</a><br /><br />";
$website = "<strong>Website:</strong> <a href='{$row['website']}' target='_blank' title='Click to visit website'>{$row['website']}</a><br /><br />";
$phone = "<strong>Telephone:</strong> {$row['phone']}<br /><br />";
$twitter = socialset($row['twitter'], 'fa fa-fw fa-twitter', 'Visit Music Director On Twitter', 'Twitter')."     ";
$facebook = socialset($row['facebook'], 'fa fa-fw fa-facebook', 'Visit Music Director On Facebook', 'Facebook')."     ";
$linkedin = socialset($row['linkedin'], 'fa fa-fw fa-linkedin', 'Visit Music Director On Linkedin', 'Linkedin')."     ";
$instagram = socialset($row['instagram'], 'fa fa-fw fa-instagram', 'Visit Music Director On Instagram', 'Instagram');
echo $description.$email.$website.$phone.$twitter.$facebook.$linkedin.$instagram."<hr class='my-4' /></div>";

else {
echo "<p style='text-align:center;' class='alert alert-danger'>This database table appears to be empty</p>";
echo "<p style='text-align:center;' class='alert alert-info'>{$records} database entries found</p>";


// include the template footer & routines

function socialset($link, $class, $title, $text) {
  if (!empty($link)) {
    return "<a href='{$link}' target='_blank'><button style='font-size:15px;' type='button' class='btn btn-success btn-rounded'><i class='$class'></i>{$text}</button></a>";
  else {
    return "<button style='font-size:15px;' type='button' class='btn btn-warning btn-rounded' disabled><i class='$class'></i>{$text}</button>";
Perhaps, one way around the problem might be if pages had an optional include field in the database which would be run during page rendering if set, perhaps ignoring the page_text, or the page_text field was also able to render php on a page. That way, people could create a page that would include their custom php, sql,css styling etc with the existing page format. Then, I could just use the code that I have made to read data from the database which was created using my custom plugins and display it.

For those coming across this info from a search or whatever,

I would suggest that you add the following to enable some default meta tags for the custom page.

define('CUSTOMPAGETITLE', 'Some page title');
define('e_PAGETITLE', eHelper::formatMetaTitle(CUSTOMPAGETITLE));
define('META_DESCRIPTION', eHelper::formatMetaDescription('Some description'));
define('META_KEYWORDS', eHelper::formatMetaKeys('some,keywords'));

This would go between


// Here...


in the above example custom page.

I define CUSTOMPAGETITLE because it is used later in the latest version of the custom page script for page title display information.

Another thing to note about plugins.

When you create a plugin with the plugin manager and you select a database table with a prefix name, you will need to edit admin_config.php and the whatever_sql.php files in the plugin folder, the database table names will have a prefix on them, for example _e107 and this will actually create the wrong table in the database, it will add the prefix again so the table will be named _e107_e107_whatever in the database, so delete the prefix in these files. If you have already created plugins in Ver 2.x you will also need to check your database for double prefix table names, using PhpMyadmin or similar and delete as required.

1 Answer

0 like 0 dislike

You can use Plugin Builder to get ideas. On the last tab select to generate frontpage and anything you need. 

Or look at _blank plugin to see examples. 

If you want to see really complex plugin written new way, check vstore plugin.  The only way how to learn this is to study somebody else code. Except some of the core plugins (new ones, not legacy ones), check plugins by Lonalore


by (1.9k points) 15 46 56
Welcome to e107 Q&A, where you can ask questions and receive answers from other members of the e107 community.
924 questions
1,326 answers
2,297 users