I am working on my first database driven php script and decided to do an online booking form with a user login ability to return and access their past orders and etc. Anyways, right now it is still only in the database design stage. I thought I had something put together properly but when I run a sql statement it is returning improper values. This is my structure Right now I have 2 entries into the database with names of noah and fff. With Noah having 2 bookings and ff having 1. When I run the following query SELECT `bookinfo`.`userID`, `bookinfo`.`bookDetails`, `userinfo`.`fName` FROM bookinfo, userinfo it returns results it should not userID bookDetails fName 7 junk noah 7 junk fff 7 trash removal noah 7 trash removal fff 8 fs noah 8 fs fff It is for whatever reason giving every user every booking detail. Noah should have the jobs "junk" and"trash removal" while fff should have fs Anything im missing with either the query or the table?
You should use a WHERE condition to link the two tables or else it just matches every entry in the first table to every entry in the second. I cant make out the column names from the screenshot but it should be something like bookinfo.userid = userinfo.userid. It is good to consider using indexed columns for the joins.
How you word the SQL statement depends on what you want returned. A WHERE clause may work, or you may want a JOIN of one kind or another.