problem with mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

problem with mysql

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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()
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

Post 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:
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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;
User avatar
RuffRyder
Forum Newbie
Posts: 11
Joined: Thu Apr 08, 2004 7:00 am
Location: Belgium

Post by RuffRyder »

damn, my bad, forgot i was dealing with an array :roll:

thx m8
Post Reply