Accessing variables outside class
I will try to explain my issue as good as I can. I have a class with
functions, the purpose of one function is to fetch information from the
database and display it. Everything works as it should, but now I need to
access some variables to use them outside my class in another file, I
don't know how this should be done so I'm wondering if someone can guide
me.
function fetch(){
$this->_select_query = '
SELECT movies_id, movies_title,
movies_director, movies_year,
movies_category_id, cat.name
FROM movies
LEFT JOIN cat ON id = movies_category_id'
or die(mysqli_error());
$this->_stmt = $this->_mysqli->prepare($this->_select_query);
$this->_stmt->execute();
$this->_stmt->bind_result($this->_select_id, $this->_select_title,
$this->_select_director, $this->_select_year,
$this->_select_category_id, $this->_select_category_name);
$this->_stmt->store_result();
while($this->_stmt->fetch()){
echo '<tr>
<td>'.$this->_select_title.'</td>
<td>'.$this->_select_director.'</td>
<td>'.$this->_select_year.'</td>
<td>'.$this->_select_category_name.'</td>
<td><a
href="index.php?form=edit&id='.$this->_select_id.'"
title="Edit movie">Edit</a></td>
<td><a href="">Delete</a></td>
</tr>
';
}
}//close function fetch
The function fetch is inside a class called movies, now on another page I
have a form to edit(update) these movies and I would like to return the
title, director etc.. inside that form so it is easy to notice what you
are changing.
Now I do know how to do this using php procedural but not with object
oriented php. As you can also notice here I echo out the whole table
(another part of the table is on a diffirent page) So because of this I
can't use $movies->fetch()
I do hope someone can give me some more information on my issue since I
feel a bit lost at this point, and while staring too much on the same code
you can become confused and mix up stuff.
Kind Regards
Edit: should I be using globals, constants ?
No comments:
Post a Comment