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:
Laplink Gold 2008 - $15 Off with Coupon Code CJM9NE
  #1  
Old September 29th, 2002, 01: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, 03: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: 6
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, 08: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, 01: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: 6
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, 09: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, 09: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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway