We help IT Professionals succeed at work.
Get Started

How to push mysql result into php array

leppis75
leppis75 asked
on
1,375 Views
Last Modified: 2013-12-12
I'm making an availability calendar with MySQL and PHP, and I'm making the following query to find out on which dates a specific apartment is reserved.

$sql = "SELECT booking_date FROM apartment_booking_date WHERE apartment_id='$apartment_id' AND ap_booking_id is not null";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
      $reserved_dates[]=$row;
}

The query returns the correct dates, but when I'm trying to check, if the active date is included in the array of reserved dates, but the condition isn't working. Here's how my condition looks like:

if(in_array($date_db_format,$reserved_dates))

I think that the reason for this failing is probably in the format of my $reserved_dates array. This is how it looks like, when I take a dump of it. The dates are correct, but I'm having arrays inside arrays, while I think, that in order for my condition to work, the arrays shouldn't be nested.

Array ( [0] => Array ( [0] => 2010-05-01 [booking_date] => 2010-05-01 ) [1] => Array ( [0] => 2010-05-02 [booking_date] => 2010-05-02 ) [2] => Array ( [0] => 2010-05-03 [booking_date] => 2010-05-03 ) [3] => Array ( [0] => 2010-05-04 [booking_date] => 2010-05-04 ) [4] => Array ( [0] => 2010-05-10 [booking_date] => 2010-05-10 ) [5] => Array ( [0] => 2010-05-11 [booking_date] => 2010-05-11 ) [6] => Array ( [0] => 2010-05-12 [booking_date] => 2010-05-12 ) [7] => Array ( [0] => 2010-05-13 [booking_date] => 2010-05-13 ) [8] => Array ( [0] => 2010-05-14 [booking_date] => 2010-05-14 ) [9] => Array ( [0] => 2010-05-15 [booking_date] => 2010-05-15 ) )

Comment
Watch Question
Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE