|
-
Apr 12th, 2007, 09:34 AM
#1
Thread Starter
Junior Member
[RESOLVED] Querying MySql through PHP...
Hey Guys!
Hey guys i need your help please.
i'm in a bit of confused. I'm building a vehicle rental system and I have created a database using MySQL that i'm successfully connecting to.
I have the following on my web page at the moment :
select Location (list/menu)
Rental Length(Days) (text field)
select Vehicle category (list/menu)
(Submit)
Hidden Field(See question below)
1-Locations are in the database and i can access database without problems
2-Rental length is where a user enters number of days(NB there's no field in database associated with this)
3-Vehicle categories are stored in the database and they are A-E and within the same table i've got a Daily_rate field where i've different rates for each category eg A=$40, B=55 etc
Now my problem:
How can i make the hidden field display results when user presses submit button.
The result should be category's daily rate * number of days entered.
Please Help!!
ps
Is it a good idea to have a Rental_length field stored in the database as well, all it's alright as it is?
Last edited by SpringBok; Apr 12th, 2007 at 09:48 AM.
-
Apr 12th, 2007, 12:14 PM
#2
Re: Querying MySql through PHP...
uhh. I don't know if I'm assuming correctly when you say "make the hidden field display results," but to give it a value of the [daily rate] * [number of days], you can just do something like:
PHP Code:
<?php
if(isset($_POST['number_of_days'])){
//query database to return the daily_rate
$q = mysql_query("SELECT daily_rate FROM tablename WHERE something='somethingelse' LIMIT 1");
if(mysql_num_rows($q) > 0){
@extract(mysql_fetch_assoc($q));
$hidden_data = $_POST['number_of_days'] * $daily_rate;
}else{
echo ":( no data returned!";
}
}
?>
<form action="rates.php" method="post">
<!-- most of your form goes here, except for submit button/hidden field -->
<?php if(isset($hidden_data)){ ?>
<input type="hidden" name="hidden_field" value="<?php echo $hidden_data; ?>" />
<?php } ?>
<input type="submit" value="Submit" />
</form>
not exactly sure why you want to do that, though.
storing a rental length would be good, too. however, I would suggest that you store prices in a separate table -- this way, you only need to change the price of "A" once for everything in this table to update. otherwise, you'd need to update every single record that had a category of "A".
-
Apr 12th, 2007, 03:45 PM
#3
Thread Starter
Junior Member
Re: Querying MySql through PHP...
Hey kows, thanks Dude I,ve got it working now. I've stored the prices in a seperate table and it's all fine
Nice One!!
Last edited by SpringBok; Apr 12th, 2007 at 03:52 PM.
-
Apr 12th, 2007, 06:33 PM
#4
Re: Querying MySql through PHP...
If you've got no further questions on this topic, please mark it as Resolved from the Thread Tools menu above the first post. Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|