Jump to content

Noah's Classifieds - How do I... many things.


nathanielh

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.