nathanielh Posted March 30, 2010 Share Posted March 30, 2010 After some playing around with it a bit, here's a list of some questions I have: Do you know how I could charge people for how much they list something for? So lets say they want to list something for $4, and anything under $10 I charge $0.20 to list... then if they charge $10 and up they get charged $.35... and so on. I want to change it so when someone registers, you get to create the password verses Noah's Classifieds creating the password automatically. I'd like to figure out how to add the search field right on the home page with a link to the advanced search option. Quote Link to comment https://forums.phpfreaks.com/topic/196931-noahs-classifieds-how-do-i-many-things/ Share on other sites More sharing options...
andrewgauger Posted March 30, 2010 Share Posted March 30, 2010 I'll bite on the first one. You can create a table that has the bounds and the charge (Charge): ID (autoincrement pri key) uBounds(dec10,2) rate(dec10,2) 1 0 .00 (assuming free posts are free) 2 10 .20 3 100 .30 4 1000 1.00 Then your MySQL query would be class priceModel{ private $pricing=array(); function __construct(){ $sql="SELECT uBounds, rate FROM charge ORDER BY uBounds"; $result=mysql_query($sql); while ($row=mysql_fetch_assoc($result)) $this->pricing[$row["uBounds"]]=$row["rate"]; } $price=new priceModel(); This will leave you with an array: pricing[0]=0 pricing[10]=.20 pricing[100]=.30 pricing[1000]=1 you can make the following function (as part of your class): function getPrice($amount){ $tmp=0; foreach ($this->pricing as $key => $arg){ if ($amount < $key) return $tmp; $tmp=$arg; } } So now you can do this: echo $price->getPrice(15); and it should print ".20" Let me know if there are bugs. Quote Link to comment https://forums.phpfreaks.com/topic/196931-noahs-classifieds-how-do-i-many-things/#findComment-1034147 Share on other sites More sharing options...
nathanielh Posted March 30, 2010 Author Share Posted March 30, 2010 Thanks for your reply. It looks extremely helpful what you did, only one problem... I don't even know enough to implement it! Do you recommend a certain book I could look for to read up more about this? Or... maybe... I should just hire you. Quote Link to comment https://forums.phpfreaks.com/topic/196931-noahs-classifieds-how-do-i-many-things/#findComment-1034254 Share on other sites More sharing options...
andrewgauger Posted March 30, 2010 Share Posted March 30, 2010 Books are good, but so is the language reference at php.net (straight from the horse's mouth) Get a good intro book (by good I mean heavy haha) from your library if they have one. Check 'em all out if there's more than one and get a feel for the language before trying something so grandiose. Happy coding. Quote Link to comment https://forums.phpfreaks.com/topic/196931-noahs-classifieds-how-do-i-many-things/#findComment-1034422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.