Hello all. I am making a website that requires put reviews into my database. I have restaurant sections. I want to have reviews stores per restaurant. When it comes to mysql data tables i can only imagen having one column for reviews then giving each picture an id to accociate with the proper web site. Is there a better way to do this that wont take too much computer time , thanks?

Dani AI

Generated

Good call by β€” keeping reviews as individual rows that reference the restaurant is the correct, scalable approach. That design avoids concatenated text fields and makes querying, filtering and moderation straightforward. already confirmed it worked; here are practical next steps to make that schema reliable and fast.

Use proper data types and integrity rules: an integer primary key for each row, a foreign-key constraint to enforce the relationship, and a timestamp column for ordering. Add an index on the foreign-key column (and a composite index like (place_id, created_at) if you frequently sort by date). Enforce value ranges server-side (rating bounds, max review length), and always use prepared statements and output escaping to prevent SQL injection and XSS (see the OWASP guidance on SQL injection prevention). For foreign-key behavior and options see the MySQL documentation on constraints.

For performance and UX: paginate reviews (or use keyset pagination for high-volume lists), cache common queries if reads dominate, and consider maintaining denormalized aggregates (review count, average rating) on the restaurant row to avoid expensive COUNT/AVG on every page load. If you need text search, use MySQL fulltext indexes (supported in modern InnoDB). Store images outside the DB (file system or object storage) and save paths in the database. For moderation, add status flags (published/pending/flagged) and keep an audit timestamp or moderator ID. If a query is slow, run EXPLAIN to see which indexes are used and adjust accordingly.

References: OWASP SQL Injection Prevention Cheat Sheet, MySQL foreign key constraints.

Recommended Answers

All 3 Replies

I would have two tables, one table that holds a list of restaurants, each with their ID. While the other table holds the reviews against them. For the review table, have a column that holds the ID of the restaurant that the review applies. When it comes to displaying the data, you could then use a MYSQL JOIN on this value to show each restaurant with all their reviews.

So the restaurant table fields:

  • PlaceID
  • Name
  • Address
  • Image

The Review Table

  • ReviewID
  • ReviewName
  • Rating
  • ReviewText
  • PlaceID

Therefore there will be a relation between the two tables based on the PlaceID, this also means that you can have multiple reviews for each restaurant.

Hope this helps :)

thanks your right and it did

Thats good, could you please mark as solved, and give rep as you feel appropriate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.