Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   IF NOT EXIST abfrage mit MySQL (https://www.delphipraxis.net/128590-if-not-exist-abfrage-mit-mysql.html)

DeddyH 2. Feb 2009 12:37

Re: IF NOT EXIST abfrage mit MySQL
 
Sicher, dass das geht? Ansonsten nochmal hier nachlesen.

milos 2. Feb 2009 12:51

Re: IF NOT EXIST abfrage mit MySQL
 
Hmm... Das konnte mir leider auch nicht helfen.

DeddyH 2. Feb 2009 12:52

Re: IF NOT EXIST abfrage mit MySQL
 
Dann kann ich Dir leider auch nicht helfen, weil ich anscheinend nicht verstehe, was Du vorhast.

milos 2. Feb 2009 13:03

Re: IF NOT EXIST abfrage mit MySQL
 
Ich möchte das dieser code ausgeführt wird:

SQL-Code:
INSERT INTO ´username´ = $botname `users` (`id`,

`username`, `password`, `banned`, `villages`, `points`, `ennobled_by`, `ally`,

`ally_titel`, `ally_found`, `ally_lead`, `ally_invite`, `ally_diplomacy`,

`ally_mass_mail`, `rang`, `villages_mode`, `attacks`, `new_report`, `new_mail`,

`market_sell`, `market_buy`, `market_ratio_max`, `killed_units_att`,

`killed_units_att_rank`, `killed_units_def`, `killed_units_def_rank`,

`killed_units_altogether`, `killed_units_altogether_rank`, `do_action`,

`last_activity`, `birthday`, `vacation_id`, `vacation_name`, `vacation_accept`,

`b_day`, `b_month`, `b_year`, `sex`, `home`, `image`, `personal_text`, `window_width`,

`show_toolbar`, `dyn_menu`, `confirm_queue`, `map_size`, `memo`, `map_reload`,

`graphical_overwiev`, `overview`, `stufen`, `winter`) VALUES (NULL, '$botname',

'e10adc3949ba59abbe56e057f20f883e', 'N', '', '', '', '-1', '', '0', '0', '0', '0',

'0', '', 'prod', '0', '0', '0', 'all', 'all', '3', '', '', '', '', '', '', '', '', '',

'-1', '', '0', '', '', '', 'x', '', '', '', '840', '1', '1', '1', '9', '', '', '1',

'new', 'yes', '');'1', '1', '1', '9', '', '', '1', 'new', 'yes', '');
Falls $botname nicht existiert. $Botname ist die variable in der config wo man auswählen muss welchen spieler er steuert

DeddyH 2. Feb 2009 13:08

Re: IF NOT EXIST abfrage mit MySQL
 
Das Einfachste wäre doch, das in 2 Schritten zu machen. Zuerst nachschauen, ob es den User bereits gibt:
SQL-Code:
SELECT COUNT(*) AS Anzahl
FROM Tabelle
WHERE username = $botname
Kommt da eine 0 zurück (kein Datensatz vorhanden), dann mit INSERT einfügen
SQL-Code:
INSERT INTO Tabelle(Feldliste) VALUES(Wertliste)
ansonsten Datensatz updaten
SQL-Code:
UPDATE Tabelle
SET Feld1 = Wert1, Feld2 = Wert2,...
WHERE username = $botname

milos 2. Feb 2009 13:13

Re: IF NOT EXIST abfrage mit MySQL
 
Wie soll ich das denn abfragen ob 0 kommt?

$usernotexists = <<<MEHRZEILEN
mysql_query("SELECT COUNT(*) AS Anzahl
FROM Tabelle
WHERE username = $botname")
MEHRZEILEN;

if ($usernotexists == 0)
{
mysql_query("INSERT INTO Tabelle(Feldliste) VALUES(Wertliste)");
}


Und noch eine Frage:
mysql_query("SELECT COUNT(*) AS Welche anzahl?
FROM Tabelle
WHERE username = $botname")

DeddyH 2. Feb 2009 13:20

Re: IF NOT EXIST abfrage mit MySQL
 
Mit der Abfrage bekommst Du eine Datenmenge mit genau einem Datensatz zurück. Dieser Datensatz enthält das Feld "Anzahl", in dem die Anzahl der User mit diesem Namen drinsteht. Und wie man das in PHP abfragt, kannst Du hier nachlesen.

milos 2. Feb 2009 13:38

Re: IF NOT EXIST abfrage mit MySQL
 
Könntest du mir eine PN schicken und mir das erklären?

DeddyH 2. Feb 2009 13:41

Re: IF NOT EXIST abfrage mit MySQL
 
Kann ich, aber erst ab 16:00 Uhr.

milos 2. Feb 2009 13:42

Re: IF NOT EXIST abfrage mit MySQL
 
Ok ich werde da sein :D xD


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:48 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz