I have a script containing the main classes for my site. I tried coping individual classes out and making each a file. Some worked and some don't. One very strange situation is that the argument "limit" in a mssql query often doesn't work. Here are the codes:
This is the class file as grants_class.php (the file to use the class follows). If I remove "limit $num" in function listgrants ($num). It works. It won't wokr even if I replace a $num with a number, or change it to $_GET['num'].
<?
class grants {
var $grants_id,
$type,
$title,
$agency,
$details,
$url,
$deadline,
$posted,
$db_table;
function grants (){
$this->db_table='grants';
}
function addgrants ($type, $title, $agency, $details, $url, $deadline){
$details = nl2br(stripslashes(FixQuotes($details, "")));
$title = nl2br(stripslashes(FixQuotes($title, "")));
$query = "insert into $this->db_table values (NULL, '$type', '$title', '$agency', '$details', '$url', '$deadline', '0', now())";
$result = mssql_query($query);
//if(!$result) die("Query didn't work. " . mssql_error());
header ("location: submitcontents.php");
}
function changegrants ($grants_id, $type, $title, $agency, $details, $url, $deadline){
$query = "update $this->db_table set type='$type', title='$title', agency='$agency', details='$details', url='$url', deadline='$deadline', posted='$posted' where grants_id='$grants_id'";
$result = mssql_query ($query);
//if(!$result) die("Query didn't work. " . mssql_error());
header ("location: submitcontents.php");
}
function listgrants ($num){
$query = "select * from grants order by grants_id limit $num";
$result = mssql_query ($query);
echo "<table>";
while ($row = mssql_fetch_array ($result)){
echo "<tr><td valign=top ><img src=\"images/news_bullet.gif\" height=15 align=top></td><td> <a href=\"index.php?op=displaygrants&grants_id=$row[grants_id]\" class=newstitle>$row[title]</a> <font size=-2>[$row[date]]</font></td></tr>";
}
echo '</table>';
}
function displaygrants ($grants_id){
$query = "select * from grants where grants_id='$grants_id' limit 1";
$result = mssql_query ($query);
$row = mssql_fetch_array ($result);
include ("header.php");
echo "<span class=\"sect_title\">GRANT OPPORTUNITIES</span> [<a href=\"submit.php?op=submitgrants\">Submit a Grant</a>]";
echo "<hr size=1 color=#FFAE00>";
echo "<b>$row[title]</b> (<i>submitted on $row[date]</i>)<br>";
if ($row[agency]!=""){echo"<i>Agency: $row[agency]</i>;";}
if ($row[deadline]!=""){echo" Deadline: $row[deadline]";}
echo"<p>$row[details]"
."<p align=left><a href=\"$row[url]\">URL Source</a></p>";
include ("footer.php");
}
}//end grants class
?>
Here is the file to use the class:
<?
include ("header.php");
include ("connect.inc.php");
//include_once("class_main.inc.php");
include_once("grants_class.php");
echo "<span class=\"sect_title\">Funding Opportunities</span> [<a href=\"submit.php?op=submitgrants\">Submit a Grant Source</a>]";
echo "<hr size=1 color=#FFAE00>";
$mygrants = new grants;
$mygrants->listgrants (99);
echo "<br>";
include ("footer.php");
?>