Forum Moderators: coopster

Message Too Old, No Replies

Display details by category

         

Davidkarate

5:41 pm on Jun 18, 2012 (gmt 0)

10+ Year Member



Hi there, I have a basic classified ads. So far users have to specify things in a description fields. Like if they are selling a car then they have to mention mileage, color, make. And if they are renting a house they mention bedrooms, bathrooms, price a month...

I am trying to make more convenient or fancy sort of by adding more options(fields) to each category.

For ex: If they are selling a car the form will be something like this:

Name:
Make:
Year:
Used:
Color:
Transmission:
.....

If it's a house:
Name:
Bedrooms:
Surface:
Monthly Price:
....

My database table looks like this:
id, title, description, price, make, mileage, surface, bedrooms, name, number, state, city.

If I can only get some ideas to start with. I am completely stuck right now.
Thanks again

Davidkarate

10:05 pm on Jun 21, 2012 (gmt 0)

10+ Year Member



Anyone with an idea?

Arfi

12:05 pm on Jun 22, 2012 (gmt 0)

10+ Year Member



I think firstly you should catagorize your discreption.
if ($car)
{ form_car();}
else if ($house)
{ form_house(); }
else
{ ...... }

rocknbil

4:01 pm on Jun 22, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Never complicate your programming with what you should do on a database level.

You're going to have some issues with attempting to homogenize diverse types, like housing and autos, with a single database table. For example, what if one requires 3 descriptor fields and the other only 4? What if there are specific options for one as opposed to the other? For example, "bedrooms" = numeric drop down list, "vehicles" = make and it's related dependency, model. Especially true since your database table

id, title, description, price, make, mileage, surface, bedrooms, name, number, state, city

is tied to housing and autos but only on a basic level and in one row.

At any rate it's an interesting puzzle, though I'm not sure you'd want to take it on. :-) I'd start like so

users_table (the ones posting the ads, they can have multiple ads)
id userid password (encrypted) fname lname email phone1 phone2 phone3 address city state_region postcode

ads_table
id adid userid title description city state_region postcode zip post_date status (item address may differ than user address; status=0 pending, 1=approved, 2=disapproved)

ad_attributes
id attribute_type attribute_name attribute_value

(Here you would enter the type {house or vehicle, etc.} the names {"bedrooms" or "make"} and possible values {multiple rows for 1, 2, 3 bedrooms, or Chevy, Dodge, Toyota, etc.})

add_attributes_join
id attribute_id adid

(this is the table that ties your actual attributes to the ad itself)

ad_attributes_dependencies
id attribute_id name value

(for sub-table dependencies, for example, auto models would be in ad attributes, the make would live here . . . )

That's a good start, all of your work would be performed on a database level with some fairly complex joined selects. It will be a bit of a brain burner, but once you sort it out it will make your programming a lot less complex and you'll be able to leverage the full power of mySQL. Then you can have an infinite number of "types" and those types can have a limited OR infinite number of attributes.