1

I have dbase named "promotion_map".: map of table

I'm trying to fetch data form this db but this not working while executing this:

$tpl->assign('prom_maps', $prom_maps->getPromotionMap());

function getPromotionMap() is defined in other php file:

<?php
require_once("../common/qDB3.class.php");

class PromotionMap extends QDB3{
    function PromotionMap($DB){
        $this->tableName = "promotion_map";
        $this->indexField = "id";
        $this->d = array(
            "id"=>"",
            "promotion_id"=>"",
            "type"=>"",
            "period"=>"",
            "name"=>"",
            "duration"=>"",
            "fee"=>"",
        );
        $this->QDB3($DB);
    }

    function getPromotionMap() {
        return $this->DB->getAssoc("SELECT * FROM `{$this->tableName}`");
    }

    function getPromotionMap($id) {
        $id = (int) $id;
        return $this->DB->getRow("SELECT * FROM `{$this->tableName}` WHERE `id` = ?", [$id]);
    }

};

What I'm doing wrong?

I expecting to get table "promotion_map" from table.

Albina
  • 1,901
  • 3
  • 7
  • 19
Andrew
  • 11
  • 2
  • What error do you see? – Islam Elbanna Jun 11 '23 at 06:29
  • Please read: [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display), then you should have seen an error like: `Fatal error: Cannot redeclare getPromotionMap() ...` – Luuk Jun 11 '23 at 09:29

1 Answers1

0

The PromotionMap class contains a definition of the getPromotionMap() method twice, which is against PHP rules.

you can rename the second method like below

function getPromotionMapById($id) {
        $id = (int) $id;
        return $this->DB->getRow("SELECT * FROM `{$this->tableName}` WHERE `id` = ?", [$id]);
}

so that you can use first method getPromotionMap() to fetch data form db