[prog] code assistance
Saint-Wolfe
wolf at wolfrising.net
Thu Oct 16 17:55:59 EST 2003
I am very much a php newbie, but trying to follow advice and few books
I've come up with this.
I have some php code I'm trying to get to work, it does properly draw
the table, except somewhere the code
is incorrect because it returns no results. Here is what it should
populate the table with:
mysql> select s_code as student_number, term, year, UPPER(c_code) as
course, dayname(date) AS date, period, status from attendance where
s_code=193586498 and term='Fall' and year=2003 and date between
'2003-09-01'and '2003-09-05';
+----------------+------+------+--------+-----------+--------
+---------------+
| student_number | term | year | course | date | period | status
|
+----------------+------+------+--------+-----------+--------
+---------------+
| 193586498 | Fall | 2003 | CP105 | Tuesday | 2 | in
attendance |
| 193586498 | Fall | 2003 | CP105 | Wednesday | 2 | in
attendance |
| 193586498 | Fall | 2003 | CP105 | Thursday | 2 | in
attendance |
| 193586498 | Fall | 2003 | CP105 | Friday | 2 | in
attendance |
| 193586498 | Fall | 2003 | GE119 | Tuesday | 3 | in
attendance |
| 193586498 | Fall | 2003 | GE119 | Thursday | 3 | in
attendance |
| 193586498 | Fall | 2003 | HI200 | Tuesday | 5 | in
attendance |
| 193586498 | Fall | 2003 | HI200 | Wednesday | 5 | in
attendance |
| 193586498 | Fall | 2003 | HI200 | Thursday | 5 | in
attendance |
| 193586498 | Fall | 2003 | HI200 | Friday | 5 | in
attendance |
| 193586498 | Fall | 2003 | WP207 | Wednesday | 6 | in
attendance |
| 193586498 | Fall | 2003 | WP207 | Thursday | 6 | in
attendance |
| 193586498 | Fall | 2003 | WP207 | Friday | 6 | in
attendance |
+----------------+------+------+--------+-----------+--------
+---------------+
does anyone happen to see any obvious mistakes?
here's the code:
<?php require_once('../Connections/connect.php'); ?>
<?php
mysql_select_db($database_connect, $connect);
$query_Code = "SELECT s_code FROM attendance where s_code=$code";
$Code = mysql_query($query_Code, $sarahconnect) or die(mysql_error());
$totalRows_Code = mysql_num_rows($Code);
?>
<?
// prime grid
for($i = 0;$i < 5; $i++) {
for($j = 0; $j < 8; $j++) {
for($k = 0; $k < 1; $k++) { // two cells per period per day
$grid[$i][$j][$k] = "";
}
}
}
// build query
$query = "select s_code, term, year, UPPER(c_code) as course,
dayname(date) AS date, period, status from attendance where
s_code=193586498 and term='Fall' and year=2003 and date between
'2003-09-01'and '2003-09-05'";
// retrieve result set
$result = mysql_db_query("db",$query);
//$numrows = mysql_num_rows($result);
// loop thru result
for($crow = 0; $crow < $numrows; $crow++) {
$res_array = mysql_fetch_assoc($result);
$period=$res_array['period'];
$status = $res_array['status'];
//$sch = str_pad($attendance, 64, "0", STR_PAD_LEFT);
// echo $course . " - " . $sch. "\n";
for($i = 0;$i < 5; $i++) {
for($j = 0; $j < 8; $j++) {
//if (substr($sch,(strlen($sch) - ($i * 8 + $j) - 1),1) == "1") {
if ( $grid[$i][$j][0] != "") { // another course scheduled for same
period
$grid[$i][$j][1] = $status;
} else {
$grid[$i][$j][0] = $status;
}
}
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> Screen</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css">
<!--
A {text-decoration:none}
//-->
</STYLE>
</head>
<body>
<BR> <br>
<? // load periods into array
$per[0] = "8:30 / 8:30";
$per[1] = "9:30 / 9:20";
$per[2] = "10:30 / 10:10";
$per[3] = "11:30 / 11:00";
$per[4] = "12:30 / 12:55";
$per[5] = "1:30 / 1:45";
$per[6] = "2:30 / 2:35";
$per[7] = "3:30 / 3:30";
$per[8] = "4:30 / 4:30";
?>
<div align="center">
<table width="70%" border="1" cellpadding="0" cellspacing="0"
id="schedule">
<tr>
<td bgcolor="#969663" width="20%" height="35"><div
align="center">MThF / TuWed</div></td>
<td bgcolor="#969663" width="16%"><div
align="center">Monday</div></td>
<td bgcolor="#969663" width="16%"><div
align="center">Tuesday</div></td>
<td bgcolor="#969663" width="16%"><div
align="center">Wednesday</div></td>
<td bgcolor="#969663" width="16%"><div
align="center">Thursday</div></td>
<td bgcolor="#969663" width="16%"><div
align="center">Friday</div></td>
</tr>
<?php
for( $j =0;$j <8;$j ++)
{
print("<tr align=center>\n");
print("<td bgcolor=969663>" . $per[$j] . "</td>");
for( $i =0;$i <5;$i ++) {
print("<td>\n");
if ($grid[$i][$j][0] == "") {
echo " ";
} else {
echo $grid[$i][$j][0];
}
print("</td>\n");
}
print("</tr>\n");
}
//print("</table>\n");
?>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($Code);
?>
More information about the Programming
mailing list