Generic table edit
Met dit script kun je een willekeurige tabel editen in bijvoorbeeld een CMS. In een kolom aan de linkerkant van je pagina heb je titels van je records. In het rechterdeel heb je een div met de details per record. Via een multi-array in config.php kun je aangeven welke velden je wilt zien.
De positie in de linkerkolom wordt onthouden dmv een combi van JavaScript en PHP. Het script maak gebruik van de mootools lib.
Voor de interactie met de database gebruik ik class.core.php en class.database.php. Voor de overzichtelijkheid heb ik die hier weggelaten.
Enjoy, en tips zijn natuurlijk welkom.
Groeten, Jan Koehoorn
Voorbeeld: http://www.jankoehoorn.nl/table_edit/
Gesponsorde koppelingen
PHP script bestanden
33 reacties op 'Generic table edit'
Gesponsorde koppelingen
bij mij doet hij het niet :(
Code (php)
1
2
3
4
5
2
3
4
5
Warning: main(../classes/class.core.php) [function.main]: failed to open stream: No such file or directory in /home/vhosts/design-xtr.nl/httpdocs/klanten/index.php on line 4
Warning: main(../classes/class.core.php) [function.main]: failed to open stream: No such file or directory in /home/vhosts/design-xtr.nl/httpdocs/klanten/index.php on line 4
Fatal error: main() [function.require]: Failed opening required '../classes/class.core.php' (include_path='.:/usr/share/pear') in /home/vhosts/design-xtr.nl/httpdocs/klanten/index.php on line 4
Warning: main(../classes/class.core.php) [function.main]: failed to open stream: No such file or directory in /home/vhosts/design-xtr.nl/httpdocs/klanten/index.php on line 4
Fatal error: main() [function.require]: Failed opening required '../classes/class.core.php' (include_path='.:/usr/share/pear') in /home/vhosts/design-xtr.nl/httpdocs/klanten/index.php on line 4
Zelf heb ik ook iets dergelijks geboowd, alleen met behulp van een XML configuratie. Diverse types als int, password, bool worden ook ondersteund. Daarnaast kunnen relaties worden vastgelegd en extra voorwaarden aan gekoppeld. Zo kunnen relationele velden door middel van ajax of een select getoond worden en wordt het bijbehorende ID ingevuld.
Dit systeem is een leuk begin, ik zie dit soort dingen liever in een object vorm, maar das persoonlijk.
Leuk en leerzaam script!
Dit systeem is een leuk begin, ik zie dit soort dingen liever in een object vorm, maar das persoonlijk.
Leuk en leerzaam script!
Ik heb hem wat aangepast, zodat hij PDO gebruikt in plaats van Jan's eigen databaseklasse. Daarbij heb ik hier en daar wat htmlentities toegevoegd.
Zie http://phphulp.ikhoefgeen.nl/scripts/1239/
Zie http://phphulp.ikhoefgeen.nl/scripts/1239/
@ Freek: ik heb er een aantal fouten uitgehaald. De validator klaagt vooral over de ampersands in de url en die zet ik er met JavaScript in. Ga ik nog even naar kijken.
Automatisch uitlezen van de velden kan wel, maar dan moet het script ook alle veldtypes ondervangen. Dat lijkt me meer iets voor versie 2.0
Automatisch uitlezen van de velden kan wel, maar dan moet het script ook alle veldtypes ondervangen. Dat lijkt me meer iets voor versie 2.0
Quote:
Jan Koehoorn schreef op 13.01.2008 09:43
@ roel: ik quote mezelf even:
@ roel: ik quote mezelf even:
Quote:
Voor de interactie met de database gebruik ik class.core.php en class.database.php. Voor de overzichtelijkheid heb ik die hier weggelaten.
:o maakt niet uit hoor Jan Koehoorn die mag je ook gerust erbij posten hoor beetje onoverzichtelijkheid maakt niet zoveel uit :^)
Vooruit maar weer:
class.core.php
class.database.php
class.core.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class core {
protected $errs;
protected $msgs;
/*
* constructor
*/
public function __construct () {
$this->errs = array ();
$this->msgs = array ();
}
/*
* setters
*/
public function set_err ($err) {
array_push ($this->errs, $err);
}
public function set_msg ($msg) {
array_push ($this->msgs, $msg);
}
/*
* getters
*/
public function get_errs () {
return $this->errs;
}
public function get_errs_html () {
if ($this->has_errs ()) {
$html = '<div class="errs">';
foreach ($this->get_errs () as $err) {
$html .= $err;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
public function get_msgs () {
return $this->msgs;
}
public function get_msgs_html () {
if ($this->has_msgs ()) {
$html = '<div class="msgs">';
foreach ($this->get_msgs () as $msg) {
$html .= $msg;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
public function has_msgs () {
return count ($this->msgs);
}
public function has_errs () {
return count ($this->errs);
}
}
?>
class core {
protected $errs;
protected $msgs;
/*
* constructor
*/
public function __construct () {
$this->errs = array ();
$this->msgs = array ();
}
/*
* setters
*/
public function set_err ($err) {
array_push ($this->errs, $err);
}
public function set_msg ($msg) {
array_push ($this->msgs, $msg);
}
/*
* getters
*/
public function get_errs () {
return $this->errs;
}
public function get_errs_html () {
if ($this->has_errs ()) {
$html = '<div class="errs">';
foreach ($this->get_errs () as $err) {
$html .= $err;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
public function get_msgs () {
return $this->msgs;
}
public function get_msgs_html () {
if ($this->has_msgs ()) {
$html = '<div class="msgs">';
foreach ($this->get_msgs () as $msg) {
$html .= $msg;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
public function has_msgs () {
return count ($this->msgs);
}
public function has_errs () {
return count ($this->errs);
}
}
?>
class.database.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class database extends core {
private $db_host;
private $db_user;
private $db_pass;
private $db_name;
protected $res;
protected $affected_rows;
protected $num_rows;
protected $insert_id;
protected $records;
public function __construct () {
parent::__construct ();
$this->db_host = '';
$this->db_user = '';
$this->db_pass = '';
$this->db_name = '';
if (!mysql_connect ($this->db_host, $this->db_user, $this->db_pass)) {
array_push ($this->errs, '<p>Connectie met DB is mislukt.</p>');
}
if (!mysql_select_db ($this->db_name)) {
array_push ($this->errs, '<p>Fout bij het selecteren van de database</p>');
}
$this->insert_id = 0;
$this->records = array ();
}
public function query ($sql) {
if (!$this->res = mysql_query ($sql)) {
array_push ($this->errs, '<p>' . mysql_errno () . ': ' . mysql_error () . '</p>');
array_push ($this->errs, '<pre>' . htmlentities (str_replace ("\t", '', $sql)) . '</pre>');
return false;
}
else {
$this->insert_id = mysql_insert_id ();
return true;
}
}
public function fetch () {
return mysql_fetch_assoc ($this->res);
}
public function get_affected_rows () {
$this->affected_rows = mysql_affected_rows ();
return $this->affected_rows;
}
public function get_num_rows () {
return mysql_num_rows ($this->res);
}
public function get_insert_id () {
if (isset ($this->insert_id)) {
return $this->insert_id;
}
else {
return false;
}
}
}
?>
class database extends core {
private $db_host;
private $db_user;
private $db_pass;
private $db_name;
protected $res;
protected $affected_rows;
protected $num_rows;
protected $insert_id;
protected $records;
public function __construct () {
parent::__construct ();
$this->db_host = '';
$this->db_user = '';
$this->db_pass = '';
$this->db_name = '';
if (!mysql_connect ($this->db_host, $this->db_user, $this->db_pass)) {
array_push ($this->errs, '<p>Connectie met DB is mislukt.</p>');
}
if (!mysql_select_db ($this->db_name)) {
array_push ($this->errs, '<p>Fout bij het selecteren van de database</p>');
}
$this->insert_id = 0;
$this->records = array ();
}
public function query ($sql) {
if (!$this->res = mysql_query ($sql)) {
array_push ($this->errs, '<p>' . mysql_errno () . ': ' . mysql_error () . '</p>');
array_push ($this->errs, '<pre>' . htmlentities (str_replace ("\t", '', $sql)) . '</pre>');
return false;
}
else {
$this->insert_id = mysql_insert_id ();
return true;
}
}
public function fetch () {
return mysql_fetch_assoc ($this->res);
}
public function get_affected_rows () {
$this->affected_rows = mysql_affected_rows ();
return $this->affected_rows;
}
public function get_num_rows () {
return mysql_num_rows ($this->res);
}
public function get_insert_id () {
if (isset ($this->insert_id)) {
return $this->insert_id;
}
else {
return false;
}
}
}
?>
@ Remco: andere host zoeken ;-)
Je kunt de classes trouwens wel omzetten naar PHP 4 al vind ik het eigenlijk niks, maar goed. Code niet gecheckt dus er kunnen nog foutjes in zitten!
core.php
class.database.php
Je kunt de classes trouwens wel omzetten naar PHP 4 al vind ik het eigenlijk niks, maar goed. Code niet gecheckt dus er kunnen nog foutjes in zitten!
core.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class core {
var $errs;
var $msgs;
/*
* constructor
*/
function core () {
$this->errs = array ();
$this->msgs = array ();
}
/*
* setters
*/
function set_err ($err) {
array_push ($this->errs, $err);
}
function set_msg ($msg) {
array_push ($this->msgs, $msg);
}
/*
* getters
*/
function get_errs () {
return $this->errs;
}
function get_errs_html () {
if ($this->has_errs ()) {
$html = '<div class="errs">';
foreach ($this->get_errs () as $err) {
$html .= $err;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
function get_msgs () {
return $this->msgs;
}
function get_msgs_html () {
if ($this->has_msgs ()) {
$html = '<div class="msgs">';
foreach ($this->get_msgs () as $msg) {
$html .= $msg;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
function has_msgs () {
return count ($this->msgs);
}
function has_errs () {
return count ($this->errs);
}
}
?>
class core {
var $errs;
var $msgs;
/*
* constructor
*/
function core () {
$this->errs = array ();
$this->msgs = array ();
}
/*
* setters
*/
function set_err ($err) {
array_push ($this->errs, $err);
}
function set_msg ($msg) {
array_push ($this->msgs, $msg);
}
/*
* getters
*/
function get_errs () {
return $this->errs;
}
function get_errs_html () {
if ($this->has_errs ()) {
$html = '<div class="errs">';
foreach ($this->get_errs () as $err) {
$html .= $err;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
function get_msgs () {
return $this->msgs;
}
function get_msgs_html () {
if ($this->has_msgs ()) {
$html = '<div class="msgs">';
foreach ($this->get_msgs () as $msg) {
$html .= $msg;
}
$html .= '</div>';
}
else {
$html = '';
}
return $html;
}
function has_msgs () {
return count ($this->msgs);
}
function has_errs () {
return count ($this->errs);
}
}
?>
class.database.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class database extends core {
var $db_host;
var $db_user;
var $db_pass;
var $db_name;
var $res;
var $affected_rows;
var $num_rows;
var $insert_id;
var $records;
function database () {
parent::core ();
$this->db_host = '***';
$this->db_user = '***';
$this->db_pass = '***';
$this->db_name = '***';
if (!mysql_connect ($this->db_host, $this->db_user, $this->db_pass)) {
array_push ($this->errs, '<p>Connectie met DB is mislukt.</p>');
}
if (!mysql_select_db ($this->db_name)) {
array_push ($this->errs, '<p>Fout bij het selecteren van de database</p>');
}
$this->insert_id = 0;
$this->records = array ();
}
function query ($sql) {
if (!$this->res = mysql_query ($sql)) {
array_push ($this->errs, '<p>' . mysql_errno () . ': ' . mysql_error () . '</p>');
array_push ($this->errs, '<pre>' . htmlentities (str_replace ("\t", '', $sql)) . '</pre>');
return false;
}
else {
$this->insert_id = mysql_insert_id ();
return true;
}
}
function fetch () {
return mysql_fetch_assoc ($this->res);
}
function get_affected_rows () {
$this->affected_rows = mysql_affected_rows ();
return $this->affected_rows;
}
function get_num_rows () {
return mysql_num_rows ($this->res);
}
function get_insert_id () {
if (isset ($this->insert_id)) {
return $this->insert_id;
}
else {
return false;
}
}
}
?>
class database extends core {
var $db_host;
var $db_user;
var $db_pass;
var $db_name;
var $res;
var $affected_rows;
var $num_rows;
var $insert_id;
var $records;
function database () {
parent::core ();
$this->db_host = '***';
$this->db_user = '***';
$this->db_pass = '***';
$this->db_name = '***';
if (!mysql_connect ($this->db_host, $this->db_user, $this->db_pass)) {
array_push ($this->errs, '<p>Connectie met DB is mislukt.</p>');
}
if (!mysql_select_db ($this->db_name)) {
array_push ($this->errs, '<p>Fout bij het selecteren van de database</p>');
}
$this->insert_id = 0;
$this->records = array ();
}
function query ($sql) {
if (!$this->res = mysql_query ($sql)) {
array_push ($this->errs, '<p>' . mysql_errno () . ': ' . mysql_error () . '</p>');
array_push ($this->errs, '<pre>' . htmlentities (str_replace ("\t", '', $sql)) . '</pre>');
return false;
}
else {
$this->insert_id = mysql_insert_id ();
return true;
}
}
function fetch () {
return mysql_fetch_assoc ($this->res);
}
function get_affected_rows () {
$this->affected_rows = mysql_affected_rows ();
return $this->affected_rows;
}
function get_num_rows () {
return mysql_num_rows ($this->res);
}
function get_insert_id () {
if (isset ($this->insert_id)) {
return $this->insert_id;
}
else {
return false;
}
}
}
?>
Om te reageren heb je een account nodig en je moet ingelogd zijn.
- Details
Door:
Jan Koehoorn- 5 jaar geleden
- 1.249 x bekeken
- Labels
- Geen tags toegevoegd.
- PHP scripts opties
- Data verwerking
- Nieuwste PHP scripts
- PHP script toevoegen


PHP hulp
0 seconden vanaf nu