selecting distinct values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #1

    selecting distinct values

    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,namel y

    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
    [code=php]
    $q1 = "select DISTINCT client_id, Category_Id from portfolio order by EntryDate desc limit 6";
    $r1 = mysql_query($q1 ) or die(mysql_error ());
    if(mysql_num_ro ws($r1)){
    while($f1 = mysql_fetch_arr ay($r1)){
    $cat_id = $f1['Category_Id'];
    $client_id = $f1['client_id'];
    $q2 = "select * from client where client_id='$cli ent_id' order by client_id desc";
    $r2 = mysql_query($q2 ) or die(mysql_error ());
    if(mysql_num_ro ws($r2)){
    while($f2 = mysql_fetch_arr ay($r2)){
    $c_name = $f2['client_name'];
    echo '<tr><td align="left" valign="top" class="text-color-deepyellow"><a href="portfolio .php?cat_id='.$ cat_id.'&client _id='.$client_i d.'" class="text-color-deepyellow_link ">'.$c_name .'</a></td></tr>';
    }
    }
    }
    }
    [/code]
    any help in this regard would be highly appreciated
    regards ,
    Omer Aslam
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    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.

    Comment

    Working...