Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP - MSSQL Abfragen ob Datensatz vorhanden ist...

Empfohlene Antworten

Veröffentlicht

Hi,

also ich habe da mal ne Frage (logisch) *g*.

Also ich will abfragen ob in einer Spalte < Nummer > schon der Wert < $nummer > existiert.

Diese Abfrage will ich über diesen Code machen:


$query = "SELECT COUNT(*) FROM TReport WHERE Nummer='$nummer'";

$result = MSSQL_QUERY($query);

if ($result == 0)

{

    print "<center>ERROR: Datensatz nicht vorhanden.</center>";

    exit();

}

Problem:

Ich bekomme aber immer als $result eine 1 zurück, egal ob der Datensatz vorhanden ist oder nicht.

Tja entweder Frage ich denn Fall falsch ab oder ich weiß auch nicht...

THX4HELP

in $result steht nur das Ergebnis des Queries drin, nicht die selektierten Werte bzw 0 wenn das Query fehlgeschlagen ist (z.b. ungueltige Syntax). Du musst aus $result mit mssql_fetch_* erst die eigentlichen Daten holen.

Probiers mal so:


$query = "SELECT COUNT(*) FROM TReport WHERE Nummer='$nummer'";
$result = MSSQL_QUERY($query);
$daten=mssql_fetch_row($result);
if ($daten[0]==0)
{
print "<center>ERROR: Datensatz nicht vorhanden.</center>";
exit();
}
[/PHP]

(ungetestet)

gruss

Michael

oder:


if(mssql_num_rows($result) == 0) {
echo "Kein Datensatz vorhanden";
}
[/php]

zum Bleistift.

super danke,

war die woche nicht on, deswegen erst so spät.

aber die letzte lösung hatte ich dann auch schon später selbst gefunden - ist eleganter als über nen array zu gehn :)

THX DePlague

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.