[Gelöst]ID sollte bei 0 Sein doch sie Steigt ohne Grund.

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Moin,
    Ich habe ein Autohaus, ich erstelle die Autos auf dem Server und Speicher sie in einer MySql Tabelle ab.
    Ich habe zum testen mal einige Autos gespawnt und habe sie dann aus meiner Tabelle gelöscht doch jetzt Steigt die ID trotzdem auch wenn kein Auto in der Tabelle ist.




    stock CreateCar(cmodel, Float:cx, Float:cy, Float:cz, Float:cr, cc1, cc2, cprice)
    {
    new query[600],query2[600],query3[1200],tempplate[30], id = 0;
    format(tempplate, 30, "Niemand");
    format(query, 600, "INSERT INTO `cars` (`id`, `owner`, `x`, `y`, `z`, `r`, `c1`, `c2`, `plate`, `model`, `price`, `mod1`, `mod2`, `mod3`, `mod4`, `mod5`, `mod6`, `mod7`, `mod8`, `mod9`, `mod10`, `mod11`, `mod12`, `mod13`, `mod14`, `mod15`, `mod16`, `mod17`)");
    format(query2, 600, "VALUES ('%d', 'Niemand', '%f', '%f', '%f', '%f', '%d', '%d', '%s', '%d', '%d', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1', '-1');",id,cx, cy, cz, cr, cc1, cc2, tempplate, cmodel, cprice);
    format(query3, 600, "%s %s",query,query2);
    mysql_query(query3);
    Car[id][car] = AddStaticVehicleEx(cmodel, cx, cy, cz, cr, cc1, cc2, -1);
    SetVehicleNumberPlate(Car[id][car], "Niemand");
    return 1;
    }

    Einmal editiert, zuletzt von GamerXIOS ()

  • Benutzt du dafür Auto_Increment?


    edit:
    Sorry, BlackAce war schneller

  • Hast du Auto_Increment drin?


    Ja habe ich :o


    new string22[320], string33[320],string44[320],string55[980];
    format(string22, sizeof(string22), "CREATE TABLE IF NOT EXISTS `cars` (`id` int(5) NOT NULL AUTO_INCREMENT,`owner` varchar(24) NOT NULL,`x` double NOT NULL,`y` double NOT NULL,`z` double NOT NULL,`r` double NOT NULL,`c1` int(2) NOT NULL,`c2` int(2) NOT NULL,`plate` varchar(118) NOT NULL,`model` int(3) NOT NULL,`price` int(10) NOT NULL");
    format(string33, sizeof(string33), "`mod1` int(10) NOT NULL,`mod2` int(10) NOT NULL,`mod3` int(10) NOT NULL,`mod4` int(10) NOT NULL,`mod5` int(10) NOT NULL,`mod6` int(10) NOT NULL,`mod7` int(10) NOT NULL,`mod8` int(10) NOT NULL,`mod9` int(10) NOT NULL,`mod10` int(10) NOT NULL");
    format(string44, sizeof(string44), "`mod11` int(10) NOT NULL,`mod12` int(10) NOT NULL,`mod13` int(10) NOT NULL,`mod14` int(10) NOT NULL,`mod15` int(10) NOT NULL,`mod16` int(10) NOT NULL,`mod17` int(10) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;");
    format(string55, sizeof(string55), "%s,%s,%s",string22,string33,string44);
    mysql_query(string55);

  • Wenn Auto_Increment in der Tabelle drin ist, steigt der Schlüssel, in deinem Fall wäre das ID, immer um eins.
    Die Lösung wäre Auto_Increment aus der Tabelle zu entfernen und ID selber zu setzen

    "Bevor ich mir Informationen aus der "Bild" hole,
    werde ich anfangen, Wahlergebnisse danach vorauszusagen,
    neben welchen Busch unsere Katze gepinkelt hat."

    Margarete Stokowski

  • Jo ID wird fortgesetzt... das verhindert das du zwei gleiche IDs bekommst. :) sollte auch so bleiben.


    Mein Tipp: Fallst du ein Zähler für die Reihenfolge brauchst erstellst du einfach noch ein Feld mit der Nummerrierung.


    MfG

  • Naja fügst einfach ein Attribut in die Tabelle ein.
    Lässte eine Variable im Script immer mit zählen... Also wenn du ein Car erstellst die Variable hochzählen^^.
    Dann tust du die Variable mit rein schreiben.


    //Edit falls du meine Lösung meinst, falls die von BlackAce meinst müsstest mir mal sagen wie du die Tabelle erstellt hast :)



    Aber ich würde die raten A_I drinnen zu lassen ;)


    MfG, SrBiN15