Reputation:
I have this code for my Calendar Booking System.
public class booking_diary
{
public $bookings;
function make_booking_array($year, $month)
{
$query = "SELECT * FROM bookings WHERE date LIKE '$year-$month%'";
$result = mysqli_query($this->link, $query) or die(mysqli_error($this->link));
$this->count = mysqli_num_rows($result);
$this->bookings = '';
while ($row = mysqli_fetch_array($result)) {
$this->bookings[] = array(
"name" => $row['name'],
"date" => $row['date'],
"start" => $row['start'],
"comments" => $row['comments'],
"adminBooked" => $row['admin']
);
}
$this->make_day_boxes($this->days, $this->bookings, $this->month, $this->year);
} // Close function
function make_day_boxes()
{
// I want to access $bookings['adminBooked'] in this function
}
}
In function make_day_boxes()
I tried to access $bookings['adminBooked']
But I get error that index adminBooked is undefined
Can anyone tell me how do I get access to value stored at 'adminBooked'?
//Why are most of here to down vote me. What is wrong if I am learning and asking my problems and questions here????
Upvotes: 0
Views: 86
Reputation: 3067
If you're trying to access a class variable in your class you need to access it with $this->
e.g. $this->bookings['adminBooked'];
But you're also creating an indexed array when you do $this->bookings[] = array
so if you want to access any of the elements within it you'll have to go to the index you are interested in.
e.g.
function make_day_boxes($index){
return $this->bookings[$index]['adminBooked'];
}
Upvotes: 2
Reputation: 839
It looks like you are creating multidimensional array.
Try accessing $this->$bookings[0]['adminBooked'];
Upvotes: 1