|
Posted by Richard Davey on 04/12/05 18:37
Hello PartyPosters,
Tuesday, April 12, 2005, 4:24:34 PM, you wrote:
P> I can't figure out what I am doing wrong, this sql string seems to
P> filter out the information I want but it duplicates the all info,
P> as 'num_rows' is total of rows in the table and not the correct
P> value of the filtered information?
P> $sql="SELECT products.productID, products.title,
P> products.number_per_box, products.stock_level, products.image,
P> users.username, users.email, users.userID FROM users, products
P> WHERE products.userID = $userID";
P> $mysql_result=mysql_query($sql,$connection);
P> $num_rows=mysql_num_rows($mysql_result);
Your query should probably be performing a join. As it stands you're
selecting all of the products where userID = $userID, but you're also
selecting all of your users regardless (SELECT blah FROM users).
What relationship does the Users table have to the Products table? You
may need something more along the lines of:
SELECT blah FROM products LEFT JOIN users ON users.UserID =
products.UserID WHERE users.UserID = $userID
But that's just a best-guess based on what you've given so far.
Best regards,
Richard Davey
--
http://www.launchcode.co.uk - PHP Development Services
"I do not fear computers. I fear the lack of them." - Isaac Asimov
Navigation:
[Reply to this message]
|