I have a block with HTML and CSS design, now I need to add 3 different dynamic data (which are in different tables) using PHP in 3 different part of the block, I would like to know how can I do that ?

Should I create a module ? And if yes, how can I show data from the module in to the block ?

Or is there any other way to do that ?

*We are using Drupal 7 !

I already tried costume block which I found by my searches, but it's not working ! Or at least, I don't know how to use it !

*I'm also looking for more secure solution !

  • The problem, if I may say, is that your question is too broad. There are many ways to achieve your goal in Drupal. Oct 10, 2016 at 9:24
  • Welcome to Drupal Answers! I am sorry, but this question is too broad. We cannot explain how to write a module and if there are other methods you could use to achieve what you are trying to do.
    – apaderno
    Oct 10, 2016 at 16:32
  • How can I show data from the module in to the block? is still a too broad question. We cannot give detailed instructions on what you have to do, nor can we write the code for you.
    – apaderno
    Oct 11, 2016 at 8:50

1 Answer 1


You mean a block like in admin/structure/block/add? When adding a block, the text configuration should be set to PHP. It's not on by default.

  • Enable module PHP filter (core) in Look in /admin/modules.
  • Go to /admin/config/content/formats and add a new format.
  • Select under 'enabled filters' PHP-evaluator.
  • When making a new block, choose the new text format.
  • Usually, only user/1 (admin) needs this, but you can add roles with access to the PHP-format.
  • The problem is when I try to add PHP codes with this method, the ckeditor will comment the PHP tags !
    – Sinf
    Oct 10, 2016 at 9:14
  • On a PHP-block you shouldn't use CKeditor - or, make up your text, copy source, switch over to PHP and paste the raw html. Add PHP-code. And don't switch back to CKeditor ;-)
    – MatthijsG
    Oct 10, 2016 at 9:31
  • I'm working on it now :) THX :p
    – Sinf
    Oct 10, 2016 at 9:47
  • Do I need to include MySQL connection before my query ? or the MySQL connection is already included when I add PHP query in to the block ?
    – Sinf
    Oct 11, 2016 at 12:18
  • Thx for the answer :p
    – Sinf
    Oct 11, 2016 at 15:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.