473,386 Members | 1,606 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,386 software developers and data experts.

retrieving data from mysql having a common value

1
Maybe I can clarify, by showing a small, sample database (here, comma-delimited):

MAKE, MODEL, PRICE, PRODUCT_LinE
Ford, Escort A, $8999, Ford Escort
Ford, Escort B, $9395, Ford Escort
Ford, Excort C, $10299, Ford Escort
Ford, Escort Z, $12199, Ford Escort
Ford, Mustang A, $18999, Ford Mustang
Ford, Mustang B, $21999, Ford Mustang
Ford, Mustang C, $23999, Ford Mustang
Ford, Mustang Z, $27999, Ford Mustang

i wanna to get all values of Ford Escort and Ford Mustang,but the Ford Escort and Ford Mustang must get only once (or print only once..)....

my result must be like this :

Ford Escort
Ford, Escort A, $8999
Ford, Escort B, $9395
Ford, Excort C, $10299
Ford, Escort Z, $12199

Ford Mustang
Ford, Mustang A, $18999
Ford, Mustang B, $21999
Ford, Mustang C, $23999
Ford, Mustang Z, $27999

-->>>>Hope that clarifies !
please reply.........
Jan 26 '08 #1
1 1435
Maybe I can clarify, by showing a small, sample database (here, comma-delimited):

MAKE, MODEL, PRICE, PRODUCT_LinE
Ford, Escort A, $8999, Ford Escort
Ford, Escort B, $9395, Ford Escort
Ford, Excort C, $10299, Ford Escort
Ford, Escort Z, $12199, Ford Escort
Ford, Mustang A, $18999, Ford Mustang
Ford, Mustang B, $21999, Ford Mustang
Ford, Mustang C, $23999, Ford Mustang
Ford, Mustang Z, $27999, Ford Mustang

i wanna to get all values of Ford Escort and Ford Mustang,but the Ford Escort and Ford Mustang must get only once (or print only once..)....

my result must be like this :

Ford Escort
Ford, Escort A, $8999
Ford, Escort B, $9395
Ford, Excort C, $10299
Ford, Escort Z, $12199

Ford Mustang
Ford, Mustang A, $18999
Ford, Mustang B, $21999
Ford, Mustang C, $23999
Ford, Mustang Z, $27999

-->>>>Hope that clarifies !
please reply.........
That's kind of tricky, but I'll try.
Okay let's assume that the databases name that your keeping these values in is "cars".

Expand|Select|Wrap|Line Numbers
  1. $allCars = mysql_query("SELECT PRODUCT_LinE FROM cars");
  2. $prod_lines = array();
  3. while($car = mysql_fetch_array($allCars)) {
  4.   $prod_lines[] = $car['PRODUCT_LinE'];
  5. }
  6. $prod_lines = array_flip(array_flip($prod_lines));
  7.  
  8. foreach($prod_lines as $line) {
  9.   echo '<strong>'.$line.'</strong><br />';
  10.   while($lineRows = mysql_fetch_array(mysql_query('SELECT * FROM cars WHERE PRODUCT_LinE = \''.$line.'\'') {
  11.     echo $lineRows['MAKE'].', '.$lineRows['MODEL'].', '.$lineRows['price'].'<br />';
  12.   }
  13. }
  14.  
There's probably a better way to do it then that, but I don't know enough SQL. Give me a buzz if you need any further help or if the script doesn't work.
I'm sure you probably know enough PHP to customize it so that the markup is accessible.
Jan 27 '08 #2

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

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
0
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
10
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data...
2
by: pmz | last post by:
Dear Group, I'm connecting in C# with remote (BSD) MySQL server with ODBC Driver, and I'm trying to find the best sollution in such problem: As I've read on MySQL manual, they have suggested...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
1
by: jimmyfo | last post by:
Hi, I recently wrote an ASP.Net web application in VS2005 and published (using VS2005 Publish feature) it to a relatively clean machine with ASP.Net 2.0 and MDAC 2.8 installed on it. However, when...
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
4
by: ghjk | last post by:
I wan to add some data using php page to mysql db. But I got the error saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.