View Full Version : auto incriment
curley
01-08-2003, 04:18 PM
hi i have a prob.
i have a database table with 2 fields and i want them to auto increment.
right the problem is i am using this query
// here we are trying to add a name
if ($action=="addcomment") {
$comment_insert = $DB_site->query("INSERT INTO `name` (`nameid`, `comment`) VALUES (null, '$comment')");
it just updates all the comments to the same one so i end up with loads of the same name???
the thing is if i use it in phpmyadmin and do the same query but change (null, '$comment')"); to this (null, 'trevor')");
it puts a new line in with the id no and trevor
what am i doing wrong ??
Xenon
01-08-2003, 04:21 PM
if you use INSERT it doesn't update any lines, it inserts a new one, that's why the command is called insert
you should use UPDATE if you want to update :)
UPDATE name SET(comment='$comment')
filburt1
01-08-2003, 04:46 PM
You can also use REPLACE INTO instead of INSERT INTO to overwrite existing lines.
curley
01-09-2003, 05:59 PM
ok so if i have you right then the insert one should put a new line in well it does that ok but then i have all the rest of them with the comment in them as well how do i get the rest to stay as they are..
what i get now is this in the picy
how do i get each line to be different
Xenon
01-09-2003, 08:07 PM
UPDATE name SET(comment='$comment') WHERE nameid=xx
replace the xx with the nameid of the uptodate line :)
curley
01-10-2003, 04:57 PM
sorry but i dont know what this bit means nameid=xx..
i tried putting $nameid
then tried the last column number (21) but it still overwrites the lot:(
curley
01-11-2003, 02:27 PM
ok i've sorted that bit out, i can now insert new lines with an id no but how do i use it now to display the newest line where i want to but leave the others as they were??
at the mo the only query i can get to work is this
//try name again
$getname=$DB_site->query_first("SELECT comment FROM name WHERE nameid=23");
$name=$getname[comment];
i have to put the id no in and then it wont go to the next one that i type in to put it into the next thread
Xenon
01-12-2003, 12:31 PM
$getname=$DB_site->query_first("SELECT comment FROM name ORDER BY nameid DESC LIMIT 1");
curley
01-12-2003, 02:27 PM
you are really great thank you very much for helping me :) i hope i can be as much help to someone sometime
curley
01-12-2003, 03:16 PM
ok i have the name inputed now and getting a unique id everytime so i have a list..
now how would i allie the id of the newest name to the thread its supposed to be for??
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.