adam291086 Posted September 16, 2008 Share Posted September 16, 2008 i have this php function function edit($id) { require_once('DbConnector.php'); $loginConnector = new DbConnector(); $getnote = $loginConnector->query("Select * FROM Notepad WHERE Id ='$id'"); while ($this->notedata = $loginConnector->fetchArray($getnote)) { $text = $this->notedata['text']; $id = $this->notedata['Id']; echo $text; } } now it gets the information from my database. But instead of echoing out the information i want to return the values of $text to be used else where within the iniation script. This is how i call upon the function $edit = new note(); $id = $_GET['id']; $edit->edit($id); Quote Link to comment https://forums.phpfreaks.com/topic/124483-solved-php-functions/ Share on other sites More sharing options...
virtualdevl Posted September 16, 2008 Share Posted September 16, 2008 function edit($id) { require_once('DbConnector.php'); $loginConnector = new DbConnector(); $getnote = $loginConnector->query("Select * FROM Notepad WHERE Id ='$id'"); while ($this->notedata = $loginConnector->fetchArray($getnote)) { $text = $this->notedata['text']; $id = $this->notedata['Id']; echo $text; } return $text; } $edit = new note(); $id = $_GET['id']; $edit_text = $edit->edit($id); Of course you may want to do some checking before you return $text, i.e., to see if it's a value. Quote Link to comment https://forums.phpfreaks.com/topic/124483-solved-php-functions/#findComment-642832 Share on other sites More sharing options...
Adam Posted September 16, 2008 Share Posted September 16, 2008 Well because you're echoing out the $text variable you can't just return the value at the end. You could try saving the outputs into one string, or an array, and then return that? To return a value simply add "return $varname;" to the end, or wherever in the function. The function will stop when it reaches return... Then you'd use something like: $text = edit($id); Adam Quote Link to comment https://forums.phpfreaks.com/topic/124483-solved-php-functions/#findComment-642839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.