• Welcome to WebsiteBaker Community Forum. Please log in or sign up.
Welcome, Guest
News
Support WebsiteBaker
Your donations will help to:
PayPal
  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!
You can donate by clicking on the button below.

Read data from database with code module.

Started by netraam, February 06, 2023, 04:06:40 PM  ( Read 11,572 times )

netraam

Hello everyone,

Is it possible to read data from the websitabaker database with the code module?
And if it is so, does someone have an example how to do it?

Thanks in advance
Maarten

    crnogorac081

    Web developer

    Gast

    take a look into the droplets and use echo (for a output) instead of return

    for example this droplet for the last modified date from this page

    global $database, $wb;
    $retVal = ' ';
    if (
    PAGE_ID > 0) {
       
    $query = $database->query("SELECT max(modified_when) FROM ".TABLE_PREFIX."pages");
       
    $mod_details = $query->fetchRow();
       
    $retVal = "This site was last modified on ".date("d/m/Y", $mod_details[0])." at ".date("H:i", $mod_details[0]).".";
    }
    echo
    $retVal;

      Gast

      additional info

      it is not possible, to work with a code-combination between PHP && HTML or with other words: you cannot use the open PHP-Tag <?php and the endtag ?> in this code module

      if you need a mixed code, use the Code² module -> https://addon.websitebaker.org/pages/en/browse-add-ons.php?id=0C49DE21

      this code²-Module is a stand-alone-module, it's not needed, to uninstall the WB-intern Code-Module, to use the Code²-Module


        \n\n