How to properly recall a function using custom MVC












0















Hi and good day to you all..
I'm new to MVC's/model-view-controller frameworks. I've made my own by reverse-engineering a custom MVC framework I've got from a friend of mine, so far it's all going good and smooth until I got to this part where I need to recall a function inside the function it self.. I'm currently creating a binary tree website and need to output values inside the table, what I'm trying to do is call a function and fetch all values and put them inside an array for later referencing.



This is my code in the model folder.



public function getGenealogy($parent) {
$this->db->sql('SELECT * FROM accounts WHERE sponsorUpline = ?');
$this->db->bindValue(1, $parent);
$this->db->execute();
while($row = $this->db->fetch()) {
echo $row['serialNumber'];
$this->getGenealogy($row['serialNumber']);
}
}


And this is my code in the controller folder



public function index() {
$memberAccounts = $this->db->getMemberAccounts();
$getDirectReferal = $this->ddrs->getDirectReferal();
$genealogy = $this->bg->getGenealogy($_SESSION['activationCode']);
$data = [
'memberAccounts' => $memberAccounts,
'getDirectReferal' => $getDirectReferal,
'genealogy' => $genealogy
];
$this->view('dashboards/dashboard', $data);
}


As you can see, I'm trying to call the function inside of the function but what happens is that it doesn't call it self, I tried doing the same method but not with MVC and it works fine.
So my conclusion is there's something wrong about my code that I can't seem to grasp.



Also it outputs the children twice but with same values.
This is my database.
This is my database
This is the output.
This is the output.



Any ideas or help would be appreciated.










share|improve this question























  • it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

    – Ali Ghalambaz
    Jan 2 at 8:54













  • @AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

    – Bryan Ruiz
    Jan 2 at 9:10
















0















Hi and good day to you all..
I'm new to MVC's/model-view-controller frameworks. I've made my own by reverse-engineering a custom MVC framework I've got from a friend of mine, so far it's all going good and smooth until I got to this part where I need to recall a function inside the function it self.. I'm currently creating a binary tree website and need to output values inside the table, what I'm trying to do is call a function and fetch all values and put them inside an array for later referencing.



This is my code in the model folder.



public function getGenealogy($parent) {
$this->db->sql('SELECT * FROM accounts WHERE sponsorUpline = ?');
$this->db->bindValue(1, $parent);
$this->db->execute();
while($row = $this->db->fetch()) {
echo $row['serialNumber'];
$this->getGenealogy($row['serialNumber']);
}
}


And this is my code in the controller folder



public function index() {
$memberAccounts = $this->db->getMemberAccounts();
$getDirectReferal = $this->ddrs->getDirectReferal();
$genealogy = $this->bg->getGenealogy($_SESSION['activationCode']);
$data = [
'memberAccounts' => $memberAccounts,
'getDirectReferal' => $getDirectReferal,
'genealogy' => $genealogy
];
$this->view('dashboards/dashboard', $data);
}


As you can see, I'm trying to call the function inside of the function but what happens is that it doesn't call it self, I tried doing the same method but not with MVC and it works fine.
So my conclusion is there's something wrong about my code that I can't seem to grasp.



Also it outputs the children twice but with same values.
This is my database.
This is my database
This is the output.
This is the output.



Any ideas or help would be appreciated.










share|improve this question























  • it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

    – Ali Ghalambaz
    Jan 2 at 8:54













  • @AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

    – Bryan Ruiz
    Jan 2 at 9:10














0












0








0








Hi and good day to you all..
I'm new to MVC's/model-view-controller frameworks. I've made my own by reverse-engineering a custom MVC framework I've got from a friend of mine, so far it's all going good and smooth until I got to this part where I need to recall a function inside the function it self.. I'm currently creating a binary tree website and need to output values inside the table, what I'm trying to do is call a function and fetch all values and put them inside an array for later referencing.



This is my code in the model folder.



public function getGenealogy($parent) {
$this->db->sql('SELECT * FROM accounts WHERE sponsorUpline = ?');
$this->db->bindValue(1, $parent);
$this->db->execute();
while($row = $this->db->fetch()) {
echo $row['serialNumber'];
$this->getGenealogy($row['serialNumber']);
}
}


And this is my code in the controller folder



public function index() {
$memberAccounts = $this->db->getMemberAccounts();
$getDirectReferal = $this->ddrs->getDirectReferal();
$genealogy = $this->bg->getGenealogy($_SESSION['activationCode']);
$data = [
'memberAccounts' => $memberAccounts,
'getDirectReferal' => $getDirectReferal,
'genealogy' => $genealogy
];
$this->view('dashboards/dashboard', $data);
}


As you can see, I'm trying to call the function inside of the function but what happens is that it doesn't call it self, I tried doing the same method but not with MVC and it works fine.
So my conclusion is there's something wrong about my code that I can't seem to grasp.



Also it outputs the children twice but with same values.
This is my database.
This is my database
This is the output.
This is the output.



Any ideas or help would be appreciated.










share|improve this question














Hi and good day to you all..
I'm new to MVC's/model-view-controller frameworks. I've made my own by reverse-engineering a custom MVC framework I've got from a friend of mine, so far it's all going good and smooth until I got to this part where I need to recall a function inside the function it self.. I'm currently creating a binary tree website and need to output values inside the table, what I'm trying to do is call a function and fetch all values and put them inside an array for later referencing.



This is my code in the model folder.



public function getGenealogy($parent) {
$this->db->sql('SELECT * FROM accounts WHERE sponsorUpline = ?');
$this->db->bindValue(1, $parent);
$this->db->execute();
while($row = $this->db->fetch()) {
echo $row['serialNumber'];
$this->getGenealogy($row['serialNumber']);
}
}


And this is my code in the controller folder



public function index() {
$memberAccounts = $this->db->getMemberAccounts();
$getDirectReferal = $this->ddrs->getDirectReferal();
$genealogy = $this->bg->getGenealogy($_SESSION['activationCode']);
$data = [
'memberAccounts' => $memberAccounts,
'getDirectReferal' => $getDirectReferal,
'genealogy' => $genealogy
];
$this->view('dashboards/dashboard', $data);
}


As you can see, I'm trying to call the function inside of the function but what happens is that it doesn't call it self, I tried doing the same method but not with MVC and it works fine.
So my conclusion is there's something wrong about my code that I can't seem to grasp.



Also it outputs the children twice but with same values.
This is my database.
This is my database
This is the output.
This is the output.



Any ideas or help would be appreciated.







php pdo






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 8:04









Bryan RuizBryan Ruiz

35




35













  • it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

    – Ali Ghalambaz
    Jan 2 at 8:54













  • @AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

    – Bryan Ruiz
    Jan 2 at 9:10



















  • it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

    – Ali Ghalambaz
    Jan 2 at 8:54













  • @AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

    – Bryan Ruiz
    Jan 2 at 9:10

















it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

– Ali Ghalambaz
Jan 2 at 8:54







it's not a good idea to have a recursive function that uses database and i think your problem is echo in getGenealogy function . you should return value not to echo it!

– Ali Ghalambaz
Jan 2 at 8:54















@AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

– Bryan Ruiz
Jan 2 at 9:10





@AliGhalambaz I'm echoing the value for development purposes, I want to see if the function is doing what it is intended to do.

– Bryan Ruiz
Jan 2 at 9:10












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003067%2fhow-to-properly-recall-a-function-using-custom-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003067%2fhow-to-properly-recall-a-function-using-custom-mvc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas