Howdy... 😉
I am trying to learn how to do OOP in PHP and it isn't that easy... 🙁
I am querying the database and getting the result...
This function works when there is only one result in the query, but if there are multiple records, I get to see the very last record returned...
So, I guess it all boils down to my fault that I do not know how to create a list of objects to return... How would I do that???
Does anybody see what I am missing here???
This is the line that calls up the function...
$db = new db($DBhost, $DBuser, $DBpass, $DBName);
$oBooking = $db->GetBookingByDate('11', '19', $userTable1);
and this is the actual function which is in seperate file...
function GetBookingByDate($month, $day, $table)
{
$month = (int) $month;
$day = (int) $day;
if (!$this->link)
{
// When connection cannot be made
echo("Error<BR>");
return -1;
}
$oBooking = new Booking();
$sql = "SELECT * ";
$sql .= " FROM $table ";
$sql .= " WHERE MONTH(`STARTDATETIME`) = '$month' AND DAYOFMONTH(`STARTDATETIME`) = '$day'";
$r = mysql_query($sql, $this->link) or die(mysql_error());
if ( mysql_num_rows($r))
{
for ($i = 0 ; $i < mysql_num_rows($r) ; $i++)
{
$row = mysql_fetch_array($r, MYSQL_ASSOC);
$oBooking->setBookingID($row["BookingID"]);
$oBooking->setTerminalID($row["TerminalID"]);
$oBooking->setStartDateTime($row["StartDateTime"]);
$oBooking->setEndDateTime($row["EndDateTime"]);
}
}
return $oBooking;
}