473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

mysql query

13
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT * FROM product, members WHERE members_username='amino'") // <= put table field here
  2. or die(mysql_error());  
  3.  
  4. while($row = mysql_fetch_array($result))
  5.   {
  6.   echo $row['product_title'] . " " . $row['product_description'] . " " . $row['product_price'];
  7.   echo "<br />";
  8.   }
  9.     mysql_free_result($result);
here is my code.
member username is amino
I want to retrieve the products he posted.
when I use this code it lists ALL THE PRODUCTS on the 'product' table

any input would be greatly appreciated.
Apr 26 '10 #1
3 1294
chathura86
227 100+
define the relationship with product and members tables in the where clause

Regards
Apr 26 '10 #2
Atli
5,058 Expert 4TB
Hey.

The problem with linking tables in that manner (listing them after the FROM clause) is that the tables are linked without any specific relationship between them. Meaning that every row in every table is linked to every row in every other table, giving you a massive table that you can't filter by any one column in any one table without getting every possible row from all the other tables.

To avoid this, you should define the relationship between the tables, like chathura86 suggested. However, I would suggest that you use the ON clause, rather than defining it in the WHERE clause. This will have MySQL link only rows that match a specific condition, like if a column in one table is equal to a column in the other table.

For instance, if I had a "product" table, which linked to a "category" table by a foreign key, I could do this to list all products by the name of the "category".
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM product AS p
  2. INNER JOIN category AS c
  3.     ON p.category_id = c.id
  4. WHERE c.name = 'Boat'
This would give me only products who's "category_id" matches the "id" of a category named "Boat"
Apr 26 '10 #3
fogsys
13
got it. thank you guys! I had to define the relationship between them
Apr 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: Cern | last post by:
Is it somebody out there who has made a migration from an Oracle server to an MySQL server?? The scenario is as simply: I've got a Oracle 8 server with a database with content that I want to...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
3
by: Me Alone | last post by:
Hello: I am trying to edit some C code I found in "The definitive guide to using, programming, and administering MySQL" by Paul DuBois. This C client program connects and then segfaults when...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.