I think I'm going insane....I keep getting this error message!!
Unknown column 'Roster' in 'where clause'
I don't know where I am going wrong. I have checked and re-checked my spelling as well!!
Here is my code....
error_reporting(E_ALL); // this should output any errors that come our way
// replace these with your credentials
$server = "localhost";
$user = "saskdiet";
$password = "w6KDheqm";
$database = "saskdiet";
// Connect to Server
mysql_connect($server, $user, $password) or die(mysql_error());
// Select Database
mysql_select_db($database) or die(mysql_error());
// Query the Database
$query = mysql_query("SELECT * FROM `sda` WHERE `Roster` =1 ORDER BY `LastName`" ) or die(mysql_error()); // replace table with your table name
// Setting page navigation variables
$limit = 25; // Default results per-page.
$page = $_GET["page"]; // Default page value.
// $page = 0;
$numrows = mysql_num_rows($query); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query");
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows % $limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
$current_record = $page * $limit;
$current_last = $current_record + $limit;
Results <b><?=$current_record?></b> - <b><?=$current_last?></b> of <b><?=$numrows?></b>
</td>
<td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
</td>
</tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr align="left" valign="top">
<td>Name</td>
<td>ID#</td>
<td>Work Address </td>
<td>Contact Info </td>
<td>Position/Employer</td>
</tr>
<?php
/* Since I dont know what the table contains I can only guess that i may not have rows thus why the while loop never executes so lets check */
$results = mysql_query("SELECT * FROM `sda` WHERE `Roster` =1 ORDER BY `LastName` ASC LIMIT $current_record, $limit");
if (mysql_num_rows($results) > 0) //test that its > 0
{
while($row = mysql_fetch_array($results))
{ echo "<tr valign=top><td><strong>" . $row["LastName"] .", " . $row["FirstName"] . "</strong></td><td>" . $row["ID"] . "</td><td>" . $row["EmployerAddress"] . "<br>" . $row["EmployerCity"] . "<br>" . $row["EmployerPostalCode"] . "</td><td><strong>H:</strong> " . $row["HomePhone"] . "<br><strong>H-Email:</strong> " . $row["HomeEmailAddress"] . "<br><strong>W:</strong> " . $row["WorkPhone"] . "<br><strong>W-Fax:</strong> " . $row["WorkFax"] . "<br><strong>W-Email:</strong> " . $row["WorkEmailAddress"] . "</td><td>" . $row["PositionTitle"] . "<br>" . $row["EmployerName"] . "</td></tr>";
// and so forth
// close the while loop
}
}
else
echo "There are no records in the Table SDA";
echo "</table>";
// page details
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - 1;
echo("<a href=\"$PHP_SELF?page=$back_page\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $i - 1;
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?page=$ppage\">$i</a> \n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + 1;
echo(" <a href=\"$PHP_SELF?page=$next_page\">next</a>");}
// Free resultset
mysql_free_result($query);