-
Notifications
You must be signed in to change notification settings - Fork 0
/
own-plugin-testing.php
77 lines (68 loc) · 2.01 KB
/
own-plugin-testing.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
73
74
75
76
77
<?php
/*
Plugin Name: SchokoDB Plugin
Author: Daniel M.
Version: 1.0
Description: Ein Plugin fuer die SchokoDB
*/
/**
* Funktion um alle Produkte auszugeben.
*
* Gibt alle Produkte der Schokofabrik in einer Tabelle zurueck.
* @return Bezeichnung aller Produkte in einer Tabelle.
*/
function schokoProdukte_func()
{
//wenn eine globale Variable verwendet wird muss man diese deklarieren
global $wpdb;
ob_start();
$res = $wpdb->get_results("SELECT * FROM Produkt");
echo '<table class="table-striped table-hover">';
foreach ($res as $r) {
?>
<tr>
<td>
<?php echo $r->bezeichnung; ?>
</td>
<td class="small">
<?php echo $r->gewicht; ?>
</td>
</tr>
<?php
}
echo '</table>';
return ob_get_clean();
}
/**
* Funktion um alle Kunden auszugeben.
*
* Gibt alle Kunden der Schokofabrik in einem Formular zurueck.
* @return Bezeichnung aller Kunden in einem Formular.
*/
function schokoKunden_func()
{
global $wpdb;
ob_start();
?>
Bitte auswählen:
<form method="GET">
<select name="kunde">
<?php
$kunden = $wpdb->get_results("SELECT * FROM Kunde");
foreach ($kunden as $k) {
echo '<option value="' . $k->firmenname . '">' . $k->firmenname . '</option>';
}
?>
</select>
<input type="submit" value="Anzeigen" class="btn btn-default">
</form>
<?php
if (isset($_REQUEST['kunde'])) {
$kundendaten = $wpdb->get_results($wpdb->prepare('SELECT * FROM Kunde WHERE firmenname = %s', $_REQUEST['kunde']));
$kunde = $kundendaten[0];
echo '<div class="well">Name: ' . $kunde->firmenname . '<br>' . 'Adresse: ' . $kunde->adresse . '<br>' . 'Telefonnummer: ' . $kunde->telefonnummer . '</div>';
}
return ob_get_clean();
}
add_shortcode('schokoProdukte', 'schokoProdukte_func');
add_shortcode('schokoKunden', 'schokoKunden_func');