I am using the following code to try and retrieve information that I have within a database.
I have creating a calender display, the name comes from the database, however the name does not appear, I have done this before and this time it is not working, in addition I have the following warnings on my page:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in c:\public_html\cal.php on line 153
Warning: extract(): First argument should be an array in c:\public_html\cal.php on line 154
The code is below, can someone spot the obvious mistake and save my sanity??
<?
//require("config.php");
/***
* This are the contents of the config file
*/
$link = mysql_connect("localhost", "team_lead_1", "");
$query = "SELECT * FROM tbl_attend";
$result = mysql_db_query("holiday", $query);
/***
*Set up variables to hold the month, date and year.
*/
if(!$currYear) { $currYear = date("Y"); }
if(!$currMonth) { $currMonth = date("n"); }
if(!$currDay) { $currDay = date("j"); }
/***
*Set up variables to display previous and next months correctly
*/
/***
*Defaults for previous month
*/
$prevMonth = $currMonth-1;
$prevYear = $currYear;
// if January, decrement year and set month to December
if ($prevMonth < 1)
{
$prevMonth=12;
$prevYear--;
}
/***
*Defaults for next month
*/
$nextMonth = $currMonth+1;
$nextYear = $currYear;
// if December, increment year and set month to January
if ($nextMonth > 12)
{
$nextMonth=1;
$nextYear++;
}
/***
*Arrays to hold the days and months and total days
*/
$days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
/***
*Check for a leap year
*/
if (date("L", mktime(0,0,0,$currMonth,1,$currYear)))
{
$totalDays[2] = 29;
}
/***
*Find the First Day of the Month
*/
$firstDayOfMonth = date("w", mktime(0,0,0,$currMonth,1,$currYear));
/***
* Find if we are at a weekend or a weekday
*/
if (($days ==0)||($days ==6)) //Sunday is 0, Saturday is 6.
{
$color = "#99FFFF";
}
else
{
$color = "#FFFFFF";
}
/***
*Begin building the calender display
*/
echo "<table border='1' cellpadding='2' cellspacing='1'>";
echo "<tr>";
$gap = ($totalDays[$currMonth] - 10); // The length for the middle column of the table.
echo "<td colspan=". ($totalDays[$currMonth] + 1 )." align=center>Attendance</td></tr>";
?>
<tr><td colspan=5 align=left><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $prevMonth; ?>&currYear=<? echo $prevYear; ?>"><font face="Arial"size="-2"><<</font></a></td>
<?
echo "<td colspan=".$gap." align=center>". $months[$currMonth] . ", " . $currYear . "</td>";
?>
<td colspan=5 align=right><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $nextMonth; ?>&currYear=<? echo $nextYear; ?>"><font face="Arial"size="-2">>></font></font></a></td>
<?
echo "<td></td></tr>";
echo "<tr>";
for ($x=0,$y=$firstDayOfMonth; $x<$totalDays[$currMonth]; $x++,$y++)
{
if (($y == 0)||($y == 6)) //Sunday is 0, Saturday is 6.
{
$color = "#99FFFF";
}
else
{
$color = "#FFFFFF";
}
echo "<td bgcolor=".$color."><font face=Arial size=-2>" . substr($days[$y],0,3) . "</font></td>";
if ($y == 6)
{
$y = -1;
}
}
echo "<td></td>";
echo "</tr>";
echo "<tr>";
for ($x=1, $y=$firstDayOfMonth; $x<=$totalDays[$currMonth]; $x++,$y++)
{
if (($y == 0)||($y == 6)) //Sunday is 0, Saturday is 6.
{
$color = "#99FFFF";
}
else
{
$color = "#FFFFFF";
}
echo "<td bgcolor=".$color."><font face=Arial size=-2>" .$x ."</font></td>";
if ($y == 6)
{
$y = -1;
}
}
echo "<td><font face=Arial size=-2>Employee Name</font></td>";
echo "</tr>";
// Now begin to look for information to populate the calender
if ($result)
{
while ($r = mysql_fetch_array($result))
{
$Attend_ID = $r["Attend_ID"];
$Date_From = $r["Date_From"];
$Date_To = $r["Date_To"];
$Duration = $r["Duration"];
$Employee = $r["Employee"];
$Mode = $r["Mode"];
// Find the Employee Name from the ID stored in tbl_attend.
$query2 = "SELECT Employee_Name FROM tbl_employee WHERE Employee_ID=".$Employee;
$E_Name = mysql_db_query("test_team_releases", $query2);
$row = mysql_fetch_assoc($E_Name);
extract($row);
// Add information to the table
for ($x=1, $y=$firstDayOfMonth; $x<=$totalDays[$currMonth]; $x++,$y++)
{
echo "<td bgcolor=white align=center><font face=Arial size=-2>.</font></td>";
if ($y == 6)
{
$y = -1;
}
}
echo "<td>".$Employee."</td>";
// echo "</td>";
echo "</tr>";
}
}
echo "</table>";
?>