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

selecting distinct values

omerbutt
638 512MB
hi everyone i am making a web site (PERSONAL PORTFOLIO) with the help of php,mysql,html, javascript and AJAX.Now in this portfolio the client enters his work experiences regarding to print media,web designing,logo designing e.t.c. now he wants that on his home page there should be last 6 entries visible.Now he problem is that for instance say there were 2 customers,namely

Omer
Mohsin

for Omer he designed a logo and for Mohsin he designed a web site
now in this case it is very simple and straight,but if both of these works means
logo designing and web site designing were done for the single customer say Omer then it should not show the name twice either means what if he has made the logo designing and web site for Omer only then omer should be visible only once.the atbles i am using are

category,client,portfolio

category holds the works for eg web page design,print media,logo designing e.t.c
client holds the names of the clients that he worked for
portfolio stores the client_id and category_id
the code that i have written is here
Expand|Select|Wrap|Line Numbers
  1. $q1 = "select DISTINCT client_id, Category_Id from portfolio order by EntryDate desc limit 6";
  2.         $r1 = mysql_query($q1) or die(mysql_error());
  3.         if(mysql_num_rows($r1)){
  4.             while($f1 = mysql_fetch_array($r1)){
  5.                 $cat_id = $f1['Category_Id'];
  6.                 $client_id = $f1['client_id'];
  7.                 $q2 = "select * from client where client_id='$client_id' order by client_id desc";
  8.                 $r2 = mysql_query($q2) or die(mysql_error());
  9.                 if(mysql_num_rows($r2)){
  10.                     while($f2 = mysql_fetch_array($r2)){
  11.                         $c_name = $f2['client_name'];
  12.                     echo '<tr><td align="left" valign="top" class="text-color-deepyellow"><a href="portfolio.php?cat_id='.$cat_id.'&client_id='.$client_id.'" class="text-color-deepyellow_link">'.$c_name.'</a></td></tr>';
  13.                     }
  14.                 }
  15.             }
  16.         }
  17.  
any help in this regard would be highly appreciated
regards ,
Omer Aslam
Mar 17 '08 #1
1 1619
mwasif
802 Expert 512MB
You need to handle this in PHP. When displaying customer name, make sure this is not the same customer you have shown last time. You can keep last customer name in a variable and update it everytime at the end of loop and compare it with the customer name coming from DB in the start of loop.

Let me know if you need more clarification.
Mar 18 '08 #2

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

Similar topics

19
by: Ben Gribaudo | last post by:
Hello! I am trying to query a MySQL table and retrieve either the earliest or the latest message in each thread. The messages are in a table with MsgID being the primary key and fThreadID...
2
by: Matik | last post by:
Hello everyone, Small and (I think) very simple quesiton;-) which makes me creazy. Let's say I have two tables listed below: T1 ==== IDX ==== 1
2
by: KoliPoki | last post by:
Greetings. I'm having a little trouble with a query. The idea is simple I need to display a list of recently unique visited URLs and the last time I visited. I have 2 table one stores the...
0
by: Andreas Håkansson | last post by:
I've been using the Muenchian method to group XML data, however I have run into a situation where I am unsure how to solve it. What I need to do is select distinct groups of items. I have an XML...
4
by: rodchar | last post by:
Hey all, Is there a way to get similar functionality as the SELECT DISTINCT records in a SQL Statement when selecting records from a dataset? thanks, rodchar
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
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
5
by: mikevde | last post by:
Hi, Can anyone confirm whether it is possible to: a) use subqueries in mySQL b) use DISTINCT TOP in mySQL? I am trying to find a way to return the top 5 results in my table. For simplicity...
1
by: sampalmer21 | last post by:
Hi, I want to join two tables together and only select the rows that don't have the same customer first name and last name (see my code below). When I run my code with the DISTINCT keyword, it...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.