Page 1 of 1

problem with mysql

Posted: Tue Apr 20, 2004 4:32 am
by RuffRyder
hi all,

got a little problem again. my table is as follows:
---------------------------------------
id | bnummer | model | width ....
---------------------------------------
id is autoincrement, bnummer is the ordernumber (i'm creating a shopping cart) now the problem is: when a customer visits my shop and he adds his first product to his cart, i used:

Code: Select all

$bestelnr = mysql_query("select bnummer from bestdetl order by id desc limit 1",$conn) + 1;
to get the last added id and its corresponding ordernumber(bnummer). then i want to add 1 to the bnummer, to make sure it's a new order, not the same order as last time he visited.
when my table is completely empty, the first record i adds gets bnummer 11, the second one i add gets bnummer 0 :?
this just won't work, can somebody help me?

grtz
RuffRyder

Posted: Tue Apr 20, 2004 4:47 am
by Wayne
you're missing a couple of steps .... mysql_query will only return TRUE(1) or FALSE(0) showing whether or not the query was successful, you still need to get the results out to find out what the value is using one of the functions like mysql_fetch_array()

Posted: Tue Apr 20, 2004 4:53 am
by RuffRyder
ok, thx
i've got this now:

Code: Select all

$query = mysql_query("select bnummer from bestdetl order by id desc limit 1",$conn);
	$bestelnr = mysql_fetch_array($query)+ 1;
but it still won't work, i'm still getting bnummer 1 as my first added product and 0 for my second, third, ... added products
:cry:

Posted: Tue Apr 20, 2004 5:44 am
by Wayne

Code: Select all

$query = mysql_query("select bnummer from bestdetl order by id desc limit 1",$conn); 
   $row = mysql_fetch_array($query);
   $bestelnr = $row['bnummer'] + 1;

Posted: Tue Apr 20, 2004 6:14 am
by RuffRyder
damn, my bad, forgot i was dealing with an array :roll:

thx m8