|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
doin calculation..
hi pple,
i have a problem which need help frm u guys! just wondering how will i be able to update the database to check if i still have avaiable bike to rent? lets say i wanna rent 5 bikes but the database only left 3 bikes. how am i suppose to do such that it will inform the user that there is no enough bikes for rent? i also wanna do such that if someone returned a bike, i am able to update with 1 more bike for rental? thx... i really need some guidance and help here.. thx thx.. |
|
#2
|
|||
|
|||
|
RE: doin calculation..
Well, you really need to do some database planning here. A very basic way to do this would be to have a table (called bikes) that has the following fields:
id - this will be a unique id for each bike available - either 0 or 1. 0 being not available, 1 being available. Then you can query the database like so: SELECT count(*) AS available_bikes FROM bikes WHERE available = 1 the number that is returned is the number of bikes available for rent. When you get a bike back (let's assume bike 4) and you want to update its availability, you would run a query like so: UPDATE bikes SET available = 1 WHERE id = 4 the same hold true when a bike is checked out and you want to update it: UPDATE bikes SET available = 0 WHERE id = 4 Hope that helps... |
|
#3
|
|||
|
|||
|
RE: doin calculation..
thxx.. but what i having now is huge database. i have 5 types of bikes, and for each type of bike, i have around 10 bikes. if given such case, how can i do it then? i cant possible give a id each for the ( 5 * 10 ) bikes?
is there any ways to do it? thx.. |
|
#4
|
|||
|
|||
|
RE: doin calculation..
in that case you could create two tables. One being the one matt showed you, and another one which has the five types of bikes. ie. it would contain an id field - being unique id of bike type, then in the table matt showed you, create another column called parent_id, and have that being the same id as the id of its type in the other table...hope that made sense..
|
|
#5
|
|||
|
|||
|
RE: doin calculation..
err.. maybe the way i phrase my idea is a little messy.. let me rephrase again..
we are a bike storage company. so when user want to get their bikes back from us... they got to fill in a bike release order form. QNS1: how would the user know that there is enough bike avaiable to taken out without them checking the database? Ex. let say if they wanna take out 5 bikes, but then we have only 3 bikes left in storage! so how to tell them there is no enough bikes to be taken out? QN2: how do we delete a record from the database when the bike is taken out and also how to add when user store their bike with us? hope you are clear with the picture.. thx ~ |
|
#6
|
|||
|
|||
|
RE: doin calculation..
I would really need to see your database structure...can you provide a dump of the structure?
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > doin calculation.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|