Beispiel #1
0
 function displayGrid($tablename, $begin)
 {
     parent::openConnection();
     if ($begin < strval($this->start) + strval($this->perPage)) {
         $this->start = 0;
         $this->end = strval($this->start) + strval($this->perPage);
     } else {
         $this->start = $begin;
         $this->end = strval($this->start) + strval($this->perPage);
     }
     $this->sql = "SELECT * FROM `{$tablename}` Limit {$this->start},{$this->perPage}";
     $this->rowOut = parent::query2DArray($this->sql);
     $this->nr_rows = parent::queryNumRows();
     $this->nr_cols = parent::queryNumCols();
     echo "<center><table border=1 width={$this->tableWidth} bordercolor={$this->borderColor} cellpadding={$this->cellPadding} cellspacing={$this->cellSpacing}>\n";
     // Get Column Headers ---------------
     if ($this->showHeader == 1 && $this->customHeader == "") {
         $this->sql = "SHOW COLUMNS FROM `{$tablename}`";
         $this->colOut = parent::query2DArray($this->sql);
         $this->nr_rows2 = count($this->colOut);
         echo "<tr>";
         for ($i = 0; $i < $this->nr_rows2; $i++) {
             echo "<td><center><b>" . $this->colOut[$i][0] . "</b></center></td>";
         }
         echo "</tr>\n";
     } elseif ($this->showHeader == 1 && $this->customHeader != "") {
         $cHeader = explode("|", $this->customHeader);
         $this->nr_rows2 = count($cHeader);
         echo "<tr>";
         for ($i = 0; $i < $this->nr_rows2; $i++) {
             echo "<td><center><b>" . $cHeader[$i] . "</b></center></td>";
         }
         echo "</tr>\n";
     }
     // Show Detail ----------------------
     for ($i = 0; $i < $this->nr_rows; $i++) {
         echo "<tr>";
         for ($j = 0; $j < $this->nr_cols; $j++) {
             echo "<td>&nbsp;" . $this->rowOut[$i][$j] . "</td>\n";
         }
         echo "</tr>\n";
     }
     echo "<br><br><tr><td colspan={$this->nr_cols}><center>\n";
     if ($this->start > 0) {
         echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?st=" . ($this->start - $this->perPage) . "\"><b>&lt;&lt</b></a>";
     }
     echo " <b> | </b> <a href=\"" . $_SERVER['PHP_SELF'] . "?st=" . (strval($this->start) + strval($this->perPage)) . "\"><b>&gt;&gt</b></a>";
     echo "</center></tr>\n";
     echo "</table></center>\n<br><br>\n";
     parent::closeConnection();
 }
Beispiel #2
0
///////////////////////////////////
// Example to Show How to get 2D
// Array AKA Recordset from a
// Database and output to screen
///////////////////////////////////
include "dbclass.php";
$a = new dbClass('localhost', 'test', 'root', 'password');
$rowOut = array();
$tblList = array();
$dbList = array();
// Set connection variables and open database connection ------------------------------------
$a->openConnection();
// Execute Single Row Query and display results ---------------------------------------------
$sql = "SELECT * FROM `test1`";
$rowOut = $a->query2DArray($sql);
$nr_rows = $a->queryNumRows();
// Number of rows in dataset
$nr_cols = $a->queryNumCols();
// Number of columns in dataset
echo "<table border=1 bordercolor=black>";
for ($i = 0; $i < $nr_rows; $i++) {
    echo "<tr>";
    for ($j = 0; $j < $nr_cols; $j++) {
        echo "<td>" . $rowOut[$i][$j] . "</td>";
    }
    echo "</tr>";
}
echo "</table><br><br>";
echo "<b>Number of Columns in Query is:</b> " . $nr_cols . "<br>";
echo "<b>Number of Rows in Query is:</b> " . $nr_rows . "<br>";
$a->closeConnection();
Beispiel #3
0
// of rows returned for a query
// and how to Insert a new record
// into an existing database table
/////////////////////////////////////
include "dbclass.php";
$a = new dbClass('localhost', 'test', 'root', 'password');
$rowOut = array();
$tblList = array();
$dbList = array();
$numRows = 0;
// Set connection variables and open database connection ------------------------------------
$a->openConnection();
// Execute Single Row Query and display results ---------------------------------------------
$sql = "SELECT * FROM `test1`;";
$rowOut = $a->queryRowArray($sql);
// Count the number of rows returned in a query ----------------------------------------------
$numRows = $a->queryNumRows();
$numCols = $a->queryNumCols();
echo "<table border=1 bordercolor=black>";
for ($i = 0; $i < $numCols; $i++) {
    echo "<tr><td><b>Column {$i}:</b></td><td>" . $rowOut[$i] . "</td></tr>";
}
echo "</table><br><br>";
echo "<b>Number of Columns in Query is:</b> " . $numCols . "<br>";
echo "<b>Number of Rows in Query is:</b> " . $numRows . "<br>";
// Execute an SQL command like INSERT or UPDATE ----------------------------------------------
$a->execCommand("INSERT INTO `test1` (column1,column2,column3,column4) VALUES ('1','2','3','4');");
$a->closeConnection();
?>