I am new here, and just signed up today. I need help figuring out an assignment I have for school. Here is what I was supposed to do:
1. Create a Web page using PHP to connect to the MySQL database and showing all the records within an HTML table.
2. Next, create a Web page that shows one record from the same database (using the primary key as an identifier).
3. Finally, create a link from the catalog page to the detail page that passes the primary key to the detail page for each record as needed.
In our lecture material, there was a tutorial for this, but it was done very badly and did not work for anyone in the class who tried it out. Don't ask me why because I am new to this, and I couldn't figure it out. Most of the other folks in my class had some php experience, but I had no experience coming into this class so I am basically lost. I managed to create a static catalog page based on the assignment code, as well as the page that has one record only on it. The lecture tutorial didn't call for a page including every record, though, nor one for the one record only page, but I created them anyway. Here they are......I'm first including the URL and then the PHP behind the page: Catalog page: http://vaf533.aisites.com/Catalog.php
Here is the code I used to create this particular page:
Code: Select all
<?php require_once('Connections/classes_assignment.php'); ?>
<?php
$maxRows_Recordsetclasses = 10;
$pageNum_Recordsetclasses = 0;
if (isset($_GET['pageNum_Recordsetclasses'])) {
$pageNum_Recordsetclasses = $_GET['pageNum_Recordsetclasses'];
}
$startRow_Recordsetclasses = $pageNum_Recordsetclasses * $maxRows_Recordsetclasses;
mysql_select_db($database_classes_assignment, $classes_assignment);
$query_Recordsetclasses = "SELECT classes.classid, classes.catalogid, classes.classtitle, classes.instructor, classes.`day`, classes.`time`, classes.description FROM classes";
$query_limit_Recordsetclasses = sprintf("%s LIMIT %d, %d", $query_Recordsetclasses, $startRow_Recordsetclasses, $maxRows_Recordsetclasses);
$Recordsetclasses = mysql_query($query_limit_Recordsetclasses, $classes_assignment) or die(mysql_error());
$row_Recordsetclasses = mysql_fetch_assoc($Recordsetclasses);
if (isset($_GET['totalRows_Recordsetclasses'])) {
$totalRows_Recordsetclasses = $_GET['totalRows_Recordsetclasses'];
} else {
$all_Recordsetclasses = mysql_query($query_Recordsetclasses);
$totalRows_Recordsetclasses = mysql_num_rows($all_Recordsetclasses);
}
$totalPages_Recordsetclasses = ceil($totalRows_Recordsetclasses/$maxRows_Recordsetclasses)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Catalog Page</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>classid</td>
<td>catalogid</td>
<td>classtitle</td>
<td>instructor</td>
<td>day</td>
<td>time</td>
<td>description</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordsetclasses['classid']; ?></td>
<td><?php echo $row_Recordsetclasses['catalogid']; ?></td>
<td><?php echo $row_Recordsetclasses['classtitle']; ?></td>
<td><?php echo $row_Recordsetclasses['instructor']; ?></td>
<td><?php echo $row_Recordsetclasses['day']; ?></td>
<td><?php echo $row_Recordsetclasses['time']; ?></td>
<td><?php echo $row_Recordsetclasses['description']; ?></td>
</tr>
<?php } while ($row_Recordsetclasses = mysql_fetch_assoc($Recordsetclasses)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordsetclasses);
?>And here is the PHP code I used for that one:
Code: Select all
<?php require_once('Connections/classes_assignment.php'); ?>
<?php
$maxRows_rsClasses = 10;
$pageNum_rsClasses = 0;
if (isset($_GET['pageNum_rsClasses'])) {
$pageNum_rsClasses = $_GET['pageNum_rsClasses'];
}
$startRow_rsClasses = $pageNum_rsClasses * $maxRows_rsClasses;
mysql_select_db($database_classes_assignment, $classes_assignment);
$query_rsClasses = "SELECT * FROM classes WHERE classes.classid=4";
$query_limit_rsClasses = sprintf("%s LIMIT %d, %d", $query_rsClasses, $startRow_rsClasses, $maxRows_rsClasses);
$rsClasses = mysql_query($query_limit_rsClasses, $classes_assignment) or die(mysql_error());
$row_rsClasses = mysql_fetch_assoc($rsClasses);
if (isset($_GET['totalRows_rsClasses'])) {
$totalRows_rsClasses = $_GET['totalRows_rsClasses'];
} else {
$all_rsClasses = mysql_query($query_rsClasses);
$totalRows_rsClasses = mysql_num_rows($all_rsClasses);
}
$totalPages_rsClasses = ceil($totalRows_rsClasses/$maxRows_rsClasses)-1;
?>
<html>
<title>Displaying One Record</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style2 {color: #009933}
body {
background-color: #CCFFFF;
}
-->
</style>
<body>
<h3 align="center" class="style1 style2">Displaying One Record from the Database </h3>
<p align="center" class="style1">Show me all the classes where the class ID is #4.</p>
<table border="1" align="center" bordercolor="#006633">
<tr>
<td align="center" bgcolor="#99CC99">Class Id</td>
<td align="center" bgcolor="#99CC99">Course Number</td>
<td align="center" bgcolor="#99CC99">Title</td>
<td align="center" bgcolor="#99CC99">Instructor</td>
<td align="center" bgcolor="#99CC99">Day</td>
<td align="center" bgcolor="#99CC99">Time</td>
<td align="center" bgcolor="#99CC99">Description</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsClasses['classid']; ?></td>
<td><?php echo $row_rsClasses['catalogid']; ?></td>
<td><?php echo $row_rsClasses['classtitle']; ?></td>
<td><?php echo $row_rsClasses['instructor']; ?></td>
<td><?php echo $row_rsClasses['day']; ?></td>
<td><?php echo $row_rsClasses['time']; ?></td>
<td><?php echo $row_rsClasses['description']; ?></td>
</tr>
<?php } while ($row_rsClasses = mysql_fetch_assoc($rsClasses)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($rsClasses);
?>Here is the so called "Index page" that was created using the lecture tutorial: http://vaf533.aisites.com/IndexPage.php You should be able to click on the class name and the description is supposed to pop up on the details page. However, when you click on mine all you get is this: http://vaf533.aisites.com/detail.php?classid=6
Here is the php code behind the "Index page" from the tutorial....I had to fix some of this just to get this to work, so this is NOT the original code from the tutorial....It was quite a headache for me, even though this should be a simple PHP page with repeating regions:
Code: Select all
<?php require_once('Connections/classes_assignment.php'); ?>
<?php
mysql_select_db($database_classes_assignment, $classes_assignment);
$query_rsClasses = "SELECT classid, catalogid, classtitle FROM classes";
$rsClasses = mysql_query($query_rsClasses, $classes_assignment) or die(mysql_error());
$row_rsClasses = mysql_fetch_assoc($rsClasses);
$totalRows_rsClasses = mysql_num_rows($rsClasses);
?>
<table width="70%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="12%"> </td>
<td width="36%">Catalog ID Number</td>
<td width="26%">Class Name</td>
<td width="26%"> </td>
</tr>
<?php do { ?>
<tr>
<td> </td>
<td><?php echo $row_rsClasses['catalogid'];?></td>
<td><a href="detail.php?classid=<?php echo $row_rsClasses['classid']; ?>"><?php echo $row_rsClasses['classtitle']; ?></a></td>
<td> </td>
</tr>
<?php } while ($row_rsClasses = mysql_fetch_assoc($rsClasses));?>
</table>Now here is the php code behind the "details page" that is supposed to display the class description information when you click on the class name:
Code: Select all
<?php require_once('Connections/classes_assignment.php'); ?>
<?php
$colname_rsClassDetail ="1";
if (isset($HTTP_GET_VARS['classid'])) {
$colname_rsClassDetail = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS
['classid'] : addslashes($HTTP_GET_VARS['classid']);
}
mysql_select_db($database_classes_assignment, $classes_assignment);
$query_rsClassDetail = sprintf("SELECT * FROM classes WHERE classid = %s", $colname_ClassDetail);
$query_rsClassDetail = mysql_query($query_rsClassDetail, $classes_assignment) or die(mysql_error());
$row_rsClassDetail = mysql_fetch_assoc($rsClassDetail);
$totalRows_rsClassDetail = mysql_num_rows($rsClassDetail);
?>
<html>This page came EXACTLY from the lectures, but I just cannot get this to work in conjunction with my Index page, and this is really getting to me. I have been working on this for 3 days and just cannot figure out what the problem is. I asked my professor for help, but she just told me to methodically build the pages over and over until I get it right, which I have done probably fifteen times having to fix the flawed code that the school provided each time, to no avail!!! Any helpful suggestions would be greatly appreciated!!! I only have a week and a half until I have to have my final project in for this class and I am not sure I will be able to get this right if I don't have some help!
Thanks in advance for anyone's help!!!