
February 22nd, 2006
01:59 AM
Neverside Newbie
Status: Offline!
Too many results from mysql query
Hey all,
I want to do a query for programs that are tied to currently logged user and for programs that are accessible to all users in general. Now I use this query
<?php
SELECT
data.id, data.title, data.file
FROM
data, access
WHERE
data.id = access.progid
AND
access.userid = '{$_SESSION['ses_nuserid']}'
OR
data.exposure = 1
ORDER BY
added
?>
I do get the particular programs but the query also throws out too many results of program accessible to all users (TIMES all rows In access table). Can somebody please show me where is my problem. I'm also adding a pic so you can see what im talking about (INFOKREDITI should be shown only once)
___________________
Right Or Wrong I'm Still The Boss

February 22nd, 2006
01:24 PM
Neversidian
Status: Offline!
is infokredit in there 2 times? try using a group by data.title or select distinct values
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

February 22nd, 2006
03:31 PM
Neverside Newbie
Status: Offline!
THANK YOU BigToach!! Distinct worked like a charm. And no infokredit is not in DB two times without Distinct the query showed infokredit as many times as there were rows in access table.
___________________
Right Or Wrong I'm Still The Boss

February 22nd, 2006
03:38 PM
Neversidian
Status: Offline!
I dont think distinct is technically the correct way for it to work, but without more info on your db design and stuff its hard to know the correct way. But if it works, dont break it trying to fix it.
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!