damnthecursed Posted April 24, 2009 Share Posted April 24, 2009 Good morning everybody! I am a slightly experienced 'procedural' programmer, but am trying out OOP and getting slightly confused. I have a variable called $value, which I am assigning as $this->value in function SearchBar. I am then running function SaveSearchBar which uses $this->value to add the inital value to the text input of my form. The problem is, I can call $this->value in SearchBar, but the value does not show up in SaveSearchBar. I tried to research this, but I must be doing something wrong? If anyone can help me with this dilemma, it would be very appeciated!! Link to code @ pastebin -> http://pastebin.com/m607963e2 Quote Link to comment https://forums.phpfreaks.com/topic/155519-solved-using-a-variable-in-class-from-function-to-function/ Share on other sites More sharing options...
JonnoTheDev Posted April 24, 2009 Share Posted April 24, 2009 Need to post your code. sorry didnt see the link Quote Link to comment https://forums.phpfreaks.com/topic/155519-solved-using-a-variable-in-class-from-function-to-function/#findComment-818368 Share on other sites More sharing options...
premiso Posted April 24, 2009 Share Posted April 24, 2009 A few pointers, avoid using short tags <? as they are not compatible in all systems. Use <?php instead. <html> <head> <title>CD Database Search Application</title> </head> <body> <?php $searchType = (isset($_GET['searchtype']))?$_GET['searchtype']:''; $Search = new Search($searchType);?> <h2>Search Database:</h2> <div id="search"> <form action="<?php echo $_SERVER['PHP_SELF'] . "?searchtype=search"; ?>" method="post"> <select name="searchtype"> <?php $Search->SaveSearchType();?> </select> <?php $Search->SaveSearchBar();?> <input type="submit" value="Search" /> </form> </div> <?php if(isset($_GET['searchtype'])) { echo "<div id=\"searchresults\">\n"; $Search->SearchBar($_POST['searchtype'], $_POST['value'], "ASC"); echo "</div><br />\n"; } ?> </body> <div><em>© Ryan Forsyth <?php echo date("Y");?><em></div> </html> As far as the save search bar not having the value, you do not pass it into the constructor, like your class is setup. And you do not call searchBar first to set the value. So it is being initiated as empty and does not get set until the SearchBar function is called. EDIT: The above code sets the searchtype in the constructor if it is set. Hope that helps you understand. Quote Link to comment https://forums.phpfreaks.com/topic/155519-solved-using-a-variable-in-class-from-function-to-function/#findComment-818371 Share on other sites More sharing options...
damnthecursed Posted April 24, 2009 Author Share Posted April 24, 2009 Excellent! I think I understand a little better on how construct works. My code is a little sloppy right now, I usually use the <?php, but I've been kind of whipping this together on my home system.. Thank you very much for your help!! Quote Link to comment https://forums.phpfreaks.com/topic/155519-solved-using-a-variable-in-class-from-function-to-function/#findComment-818397 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.