Auch wenn du mit Buchstaben durchnummerierst, macht es das Design nicht besser.
Normalisierung (Datenbank) ? Wikipedia
Boolesche Werte in MySQL
Einklappen
X
-
ich habe gerade meine SQL-Abfrage korrigiert
also für Datenbank normalisieren muss man doch studieren
[I]Zitat von h3ll Beitrag anzeigenDie Tabelle ist nicht normalisiert. Dann wären deine Spalten nicht durchnummeriert.
/**Ich komme nicht weiter Vielleicht kann mir jemand weiterhelfen
Einen Kommentar schreiben:
-
Die Tabelle ist nicht normalisiert. Dann wären deine Spalten nicht durchnummeriert.
Einen Kommentar schreiben:
-
Erst mal danke für die Antwort!
Sry für die schlechte SQL Tabelle. int(1) wurde ersetzt mit tinyint(1) und sql tabelle wurde normalisiert.
Irgendwie scheint das nicht zu funktionierenPHP-Code:public function getProducts($uname)
{
global $db;
$today = date("Y/n/j", time());
$current_month = date("n", $this->time);
$current_year = date("Y", $this->time);
$current_month_text = date("F Y", $this->time);
$total_days_of_current_month = date("t", $this->time);
$order = "id DESC";
$sql = "SELECT DISTINCT p.*, b.*, u.*, DATE_FORMAT(p.date, '%d.%m.%Y') as created,"
. "\n DATE_FORMAT(date_start,'".$this->short_date."') AS sdate,"
. "\n DATE_FORMAT(time_start,'%H:%i') AS stime,"
. "\n DATE_FORMAT(date_end,'".$this->short_date."') AS edate,"
. "\n DATE_FORMAT(time_end,'%H:%i') AS etime"
. "\n FROM products AS p"
. "\n LEFT JOIN payments AS b ON p.id = b.product_id"
. "\n LEFT JOIN usersettings AS u ON u.uid = '".$uname."'"
. "\n WHERE date_start BETWEEN '$current_year/$current_month/01'"
. " \n AND '$current_year/$current_month/$total_days_of_current_month'"
. "\n AND p.approved= 'yes'"
. "\n AND p.active = '1'"
. "\n AND b.status = '1'"
. "\n AND u.budget_a = '1'"
. "\n AND u.budget_b = '1'"
. "\n AND u.budget_c = '1'"
. "\n AND u.budget_d = '1'"
. "\n AND u.budget_d = '1'"
. "\n AND u.budget_f = '1'"
. "\n AND u.budget_g = '1'"
. "\n AND u.budget_h = '1'"
. "\n AND u.gebiet_a = '1'"
. "\n AND u.gebiet_b = '1'"
. "\n AND u.gebiet_c = '1'"
. "\n AND u.gebiet_d = '1'"
. "\n AND u.gebiet_e = '1'"
. "\n AND u.gebiet_f = '1'"
. "\n AND u.gebiet_g = '1'"
. "\n AND u.gebiet_h = '1'"
. "\n AND u.gebiet_i = '1'"
. "\n AND u.gebiet_j = '1'"
. "\n AND u.gebiet_k = '1'"
. "\n AND u.gebiet_l = '1'"
. "\n AND u.gebiet_m = '1'"
. "\n AND u.gebiet_n = '1'"
. "\n AND u.gebiet_o = '1'"
. "\n AND u.gebiet_p = '1'"
. "\n AND u.service_a = '1'"
. "\n AND u.service_b = '1'"
. "\n AND u.service_c = '1'"
. "\n AND u.service_d = '1'"
. "\n AND u.service_e = '1'"
. "\n AND u.service_f = '1'"
. "\n AND u.service_g = '1'"
. "\n AND u.service_h = '1'"
. "\n AND u.service_i = '1'"
. "\n AND u.service_j = '1'"
. "\n AND u.service_k = '1'"
. "\n AND u.service_l = '1'"
. "\n AND u.service_n = '1'"
. "\n AND u.service_m = '1'"
. "\n AND u.service_o = '1'"
. "\n AND u.service_p = '1'"
. "\n AND u.service_q = '1'"
. "\n AND u.service_r = '1'"
. "\n AND u.service_s = '1'"
. "\n AND u.service_t = '1'"
. "\n AND u.service_u = '1'"
. "\n AND u.service_v = '1'"
. "\n AND u.service_w = '1'"
. "\n AND u.service_y = '1'"
. "\n AND u.service_z = '1'"
. "\n AND u.service_aa = '1'"
. "\n AND u.service_bb = '1'"
. "\n AND u.service_cc = '1'"
. "\n AND u.service_dd = '1'"
. "\n AND u.service_ee = '1'"
. "\n AND u.service_ff = '1'"
. "\n AND u.service_gg = '1'"
. "\n AND u.service_hh = '1'"
. "\n AND u.service_ii = '1'"
. "\n AND u.service_jj = '1'"
. "\n AND u.service_kk = '1'"
. "\n AND u.service_ll = '1'"
. "\n AND u.service_nn = '1'"
. "\n AND u.service_mm = '1'"
. "\n AND u.service_oo = '1'"
. "\n AND u.service_pp = '1'"
. "\n AND u.service_qq = '1'"
. "\n AND u.service_rr = '1'"
. "\n AND u.service_ss = '1'"
. "\n AND u.service_tt = '1'"
. "\n AND u.service_uu = '1'"
. "\n AND u.service_vv = '1'"
. "\n AND u.service_ww = '1'"
. "\n AND u.service_yy = '1'"
. "\n AND u.service_zz = '1'"
. "\n AND u.service_aaa = '1'"
. "\n AND u.service_bbb = '1'"
. "\n AND u.service_ccc = '1'"
. "\n AND u.service_ddd = '1'"
. "\n AND u.service_eee = '1'"
. "\n AND u.service_fff = '1'"
. "\n AND u.service_ggg = '1'"
. "\n AND u.service_hhh = '1'"
. "\n AND u.service_iii = '1'"
. "\n AND u.service_jjj = '1'"
. "\n AND u.service_kkk = '1'"
. "\n AND u.service_lll = '1'"
. "\n AND u.service_nnn = '1'"
. "\n AND u.service_mmm = '1'"
. "\n AND u.service_ooo = '1'"
. "\n AND u.service_ppp = '1'"
. "\n AND u.service_qqq = '1'"
. "\n ORDER BY " . $order;
$row = $db->fetch_all($sql);
return $row;
}
Zuletzt geändert von hamalblues; 19.02.2011, 20:51.
Einen Kommentar schreiben:
-
Hallo,
diese Datenbank sieht nicht normalisiert aus. Für boolesche Werte gibt es geeignetere Datentypen als int(1). Prüfen/filtern kann man sie ganz normal mit einer Where-Klausel: WHERE bool_spalte = 1
Gruß,
Amica
Einen Kommentar schreiben:
-
Boolesche Werte in MySQL
Hallo,
ich weiß nicht wonach ich suchen soll, weil ich mein Problem nicht so einfach beschreiben kann
ich habe folgendes Problem, bzw. ich finde keinen funktionierenden Weg.
Die Datenbank ist folgendermaßen aufgebaut:
--
-- Tabellenstruktur für Tabelle `products`
--
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`service_a` int(1) NOT NULL,
`service_b` int(1) NOT NULL,
`service_c` int(1) NOT NULL,
`service_d` int(1) NOT NULL,
`service_e` int(1) NOT NULL,
`service_f` int(1) NOT NULL,
`service_g` int(1) NOT NULL,
`service_h` int(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
--
-- Tabellenstruktur für Tabelle `usettings`
--
CREATE TABLE IF NOT EXISTS `usettings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`service_a1` int(1) NOT NULL DEFAULT '1',
`service_a2` int(1) NOT NULL DEFAULT '1',
`service_b1` int(1) NOT NULL DEFAULT '1',
`service_b2` int(1) NOT NULL DEFAULT '1',
`service_c1` int(1) NOT NULL DEFAULT '1',
`service_c2` int(1) NOT NULL DEFAULT '1',
`service_d1` int(1) NOT NULL DEFAULT '1',
`service_d2` int(1) NOT NULL DEFAULT '1',
`service_e1` int(1) NOT NULL DEFAULT '1',
`service_e2` int(1) NOT NULL DEFAULT '1',
`service_f1` int(1) NOT NULL DEFAULT '1',
`service_f2` int(1) NOT NULL DEFAULT '1',
`service_g1` int(1) NOT NULL DEFAULT '1',
`service_g2` int(1) NOT NULL DEFAULT '1',
`service_h1` int(1) NOT NULL DEFAULT '1',
`service_h2` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ich möchte eine SQL-Abfrage machen, welche mir nur die Boolesche Werte deren Status 1 gesetzt wurde (Standard sind die Bits vom usettings true) "zeilenweise" die mySQL Daten in Tabelle products anzeigt.Stichworte: -
Einen Kommentar schreiben: