General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 29th, 2002, 02:15 AM
noven noven is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 6 noven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry joining few tables

i want to display both records on either member's favourite and non favourite items

like

product A [tick]
product B []
product C [tick]
..

if people like the product and it's stored as their favourite product [tick will show beside the product]

database using
product: id, product name
favourite: product_id, member_id

please help..
noven

Reply With Quote
  #2  
Old October 22nd, 2002, 04:27 PM
JayeshJain JayeshJain is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Auckland,New Zealand
Posts: 31 JayeshJain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Hi

I shall try to answer this in PHP/MySQL

assuming userid is stored in member_id

mysql_connect($host,$UserName,$Password) ;
mysql_select_db("mydatabase");
$query="select * from product";
$result=mysql_query($query);
while($row =mysql_fetch_array($result))
{
echo $row['product name'];
$product_id = $row['id']
$query1="select * from favourite where product_id = " . $productid . " and member_id = ". $member_id;
$result1=mysql_query($query1);
if mysql_num_rows($result1) <> 0
{
echo "[Tick]";
}
}

Hope this helps

Cheers
Jayesh Jain

Reply With Quote
  #3  
Old October 22nd, 2002, 09:49 PM
noven noven is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 6 noven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face

i know, but it will make the server so busy

let say if i have 10 listing records per page
and it will do 11 queries.... per page

what i need is i just want 1 query which can do the whole lots

but thanks for your effort anyway..
noven

Reply With Quote
  #4  
Old October 23rd, 2002, 02:08 AM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to Lindset Send a message via AIM to Lindset
not sure if this is the optimal way to do it, but here's something you can try out

SELECT p.id, p.name, count(f.product_id) AS checked FROM products AS p LEFT JOIN favourites AS f ON p.id = f.product_id AND f.member_id = $member_id GROUP BY p.id

btw, I'm using left join so that no rows will be left out even if there weren't a match (like you said, you wanted to display the non checked products too)

if you want to display only the checked products, just replace LEFT JOIN with INNER JOIN
__________________
Best Regards,
Håvard Lindset

Reply With Quote
  #5  
Old November 7th, 2002, 10:02 AM
noven noven is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 6 noven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Arrow is it possible to use more table with left join?

hmm..

it's good...

is it possible to have more than 2 tables using left join?
like table a, table b, table c ...

if so how to write the statement?

thanks a lots
noven

Reply With Quote
  #6  
Old November 7th, 2002, 10:53 AM
noven noven is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 6 noven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking

I found the solution

don't need to worry AS Below:

SELECT * FROM a,b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key) WHERE b.key=d.key

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > joining few tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek