I have this db below. I wonder how I should use the ID to identify each record.
Everything is connected from the classified_table!
Two Questions:
Should I use AI on every PK in this case?
Could somebody give me the FULL code for selecting an entire classified from only an ad_id (“bmw_330ci_8939483” for example)?
I am new to normalized db and making a good database work, so detailed instructions is very much appreciated… Also if you notice any ‘wrongs’ in this db please let me know.
category table:
cat_id (PK)
cat_name
category_options table:
option_id (PK)
cat_id (FK)
option_name
option_values table:
value_id (PK)
option_id (FK)
value
classifieds table:
classified_id (PK)
ad_id (VARCHAR) something like "Bmw330ci_28238239832" which will appear in URL
poster_id (FK)
cat_id (FK)
area_id (FK)
headline
description
price
etc....
posters table:
poster_id (PK)
name
email
tel
password
area table:
area_id (PK)
area
community
Thanks
I would auto-increment (AI) on fields that I would do majority of searching by. AI makes it easier to return results, but there are performance issues where it can slow down the database.
In regards to the query, I am not exactly sure what you would want to return, but this query returns the
classified_idby the givenad_idTo perform a single insert into your classifieds table and column ad id the value audi a4 would be:
Or multiple inserts using the same table, multiple fields and multiple values would be:
Notice I left out
classified_idbecause if you choose to auto-increment it will automatically assign a value without you explicitly assigning one.Check out MySQL :: Building a Database-Driven Website using PHP and MySQL for more tutorials.