Skip to content

Commit 12c6f45

Browse files
committed
first draft including paging, fields filter for item view
1 parent f6d167b commit 12c6f45

File tree

4 files changed

+299
-132
lines changed

4 files changed

+299
-132
lines changed

mysql.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,35 @@ function getColumns($table) {
8181
* Get a row from a table.
8282
* @param str table
8383
* @param str where
84+
* @param str[] contains requested columns
8485
* @return resource A resultset resource
8586
*/
86-
function getRow($table, $where) {
87-
return mysql_query(sprintf('SELECT * FROM %s WHERE %s', $table, $where));
87+
function getRow($table, $where, $fields = NULL) {
88+
$inject = '';
89+
if($fields == NULL) $inject = "*";
90+
else {
91+
$fieldnames = explode(',', $fields);
92+
foreach($fieldnames as $field) {
93+
$inject .= $field . ',';
94+
}
95+
// remove redundant comma
96+
$inject = substr($inject, 0, strlen($inject)-1);
97+
}
98+
return mysql_query(sprintf('SELECT %s FROM %s WHERE %s', $inject, $table, $where));
8899
}
89100

90101
/**
91102
* Get the rows in a table.
92103
* @param str primary The names of the primary columns to return
93104
* @param str table
105+
* @param int from lowerbound for the LIMIT
106+
* @param int to denoting the interval starting at lowerbound
107+
* @param str[] sort contains columns for sorting purposes
108+
* @param str[] filter contains search criteria for the rows
94109
* @return resource A resultset resource
95110
*/
96-
function getTable($primary, $table) {
97-
return mysql_query(sprintf('SELECT %s FROM %s', $primary, $table));
111+
function getTable($primary, $table, $from, $to, $sort = NULL, $filter = NULL) {
112+
return mysql_query(sprintf('SELECT %s FROM %s LIMIT %d, %d', $primary, $table, $from, $to));
98113
}
99114

100115
/**

phprestsql.ini

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[settings]
22
baseURL = "/phprestsql"
3+
paging = 20
34

45
[database]
56
type = "mysql"

0 commit comments

Comments
 (0)