//simpleclass.php
<?PHP
function OpenDB($db) {
if ($db == NULL or $db == '') $db = 'dbname';
//connect to MySQL
mysql_connect('dbhose', 'dbuser', 'dbpassword');
mysql_select_db('dbname');
}
function getQuery($sql) {
return mysql_query($sql);
}
function getCount($query) {
if ($query) { return mysql_num_rows($query); } else { return 0; }
}
class aRow {
var $rows='';
function listRows() {
$sql='SELECT * FROM yourtable WHERE 1;';
OpenDB('dbname'); $query=getQuery($sql);
$string = '
<table border="1" cellpadding="0" cellspacing="0" width="100%" class="datagrid">
<tr class="tblhdr">
<th>COL 01</th>
<th>COL 02</th>
<th>COL 03</th>
</tr>';
if (getCount($query) > 0) {
while ($row=mysql_fetch_assoc($query)) {
$string .= '
<tr class="gridrow" id="row'.$row['id'].'" onclick="editRow('.$row['id'].');" onmouseover="chgColor('.$row['FileID'].',1);" onmouseout="chgColor('.$row['id'].',0);">
<td>'.$row['col01'].'</td>
<td>'.$row['col02'].'</td>
<td>'.$row['col03'].'</td>
</tr>';
}
}
$string .= '</table>';
return($string);
}
function editRow($id) {
$sql = 'SELECT * FROM yourtable WHERE id = '.$id.' LIMIT 1;';
OpenDB(''); $query=getQuery($sql);
$row=mysql_fetch_assoc($query);
if ($row) {
$string = '
<form name="editRow" method="post">
COL 01 <input name="col01" id="col01ID" type="text" value="'.$row['col01'].'" /><br />
COL 02 <input name="col02" id="col02ID" type="text" value="'.$row['col02'].'" /><br />
COL 03 <input name="col03" id="col03ID" type="text" value="'.$row['col03'].'" /><br />
<input name="editRow" type="submit" value="Save Changes" />
<input name="id" type="hidden" value="'.$id.'" />
</form>';
return($string);
} else { return("<p>What's up doc?</p>"); }
}
function wrtRow($id) {
$sql = 'UPDATE yourtable SET
`col01` = "'.$_POST['col01'].'",
`col02` = "'.$_POST['col02'].'",
`col03` = "'.$_POST['col03'].'"
WHERE id = '.$id;
$query=getQuery($sql);
echo $sql;
if($query) { return(1); } else { return(0); }
}
}
?>