Jump to content

Recommended Posts

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

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.

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!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.