PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 24, 2017 8:00 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu May 19, 2016 11:12 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4335
Location: United Kingdom
We are building this system for users to add products, but we have added a means to block the user.

Now we need to look for all products for a given category name, but NOT if the user is blocked.

Trouble is, the code here is using a.id and p.id and it reckons they are not unique.

Syntax: [ Download ] [ Hide ]
SQL query: Documentation

SELECT a.id, p.id, title, catid, p.catname, price, userid, status FROM products AS p, admin AS a INNER JOIN products AS p on p.userid = a.id WHERE p.catname =:category AND a.status <> 'block'

MySQL said: Documentation
#1066 - Not unique table/alias: 'p'


So how do I do it? I think I got the "admin AS a" etc part wrong.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Thu May 19, 2016 12:25 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6348
Location: Montreal, Canada
Specify your products table in the FROM or the JOIN, but not both.

Syntax: [ Download ] [ Hide ]
SELECT a.id, p.id, title, catid, p.catname, price, userid, STATUS
FROM admin AS a
INNER JOIN products AS p ON p.userid = a.id
WHERE p.catname =:category AND a.STATUS <> 'block'

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group