Minase Posted June 29, 2008 Share Posted June 29, 2008 hy.i have a problem with a script.i do have users info into a DB, table info. i did use "while(something) {}" to echo all of its content. my question is how i can find the duplicate info? they have ID (user ID) and IID (Info ID) what i want to do is to find the duplicate values and when the while statement find the duplicate to pass over it. it is possible? or cause it parse every item one after another is not possible?thank you Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/ Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 You're not being very clear but I would try using the DISTINCT keyword in your query to remove duplicates. SELECT DISTINCT * FROM tblUsers Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577292 Share on other sites More sharing options...
Minase Posted June 29, 2008 Author Share Posted June 29, 2008 distinct doesnt work here. just a part of my code $cquery2 = "SELECT * FROM `" . DBPREFIX . "info` WHERE ID=" . $db->qstr1($user->ID); $results = mysql_query($cquery2); while ($item = mysql_fetch_row($results)) { // echo db rows and i want to check for duplicate in column IID.so if the item was displayed above,pass over it. } thanks Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577303 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 Surely with your selecting a specific ID only one record will be returned anyway? Wouldn't SELECT ID, DISTINCT(IID) work? Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577305 Share on other sites More sharing options...
PFMaBiSmAd Posted June 29, 2008 Share Posted June 29, 2008 Minase, you need to be real specific about what you are trying to do and showing a specific example of some data and what result you want would help. DISTINCT operates on the rows in the result set. It does not select distinct values in a column unless the select clause only selects that single column. You would need to do a GROUP BY to condense rows with same values into single rows. Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577315 Share on other sites More sharing options...
Minase Posted June 29, 2008 Author Share Posted June 29, 2008 ok here is my table scheme UID -auto increment ID - User ID (cause this is not primary table for users ,is just info) IID - Info ID Active - If info is active Kind - kind of info this is my DB structure now i do have the php script $cquery2 = "SELECT * FROM `" . DBPREFIX . "info` WHERE ID=" . $db->qstr1($user->ID); $results = mysql_query($cquery2); while ($item = mysql_fetch_row($results)) { $item20 = "SELECT * FROM `" . DBPREFIX . "items` WHERE `ID` = " . $item[2]; $item19 = $db->getRow($item20); echo ' <td'.$ht.'><img src="img/i/'.$item19->Img.'.jpg" alt="'.$item19->Name.'" ></td> <td'.$ht.'><strong>'.$item19->Name.' '.$activated.'</strong><br> Number: '.$countt.' '; } the variables are no problem dont worry,they are declared,but did not put all of them here cause is just plain html based on some factors. the above script will return: lets say we do have 3 rows in DB <td><img src="img/i/13.jpg" alt="Name" ></td> <td><strong>Name</strong><br> Number: 30 <td><img src="img/i/13.jpg" alt="Name" ></td> <td><strong>Name</strong><br> Number: 30 <td><img src="img/i/14.jpg" alt="Name" ></td> <td><strong>Name</strong><br> Number: 20 i did try to show exactly my "problem". the first 2 results are the same and i want if 2 or more results are duplicate to step over it (the uniq part is the IID) i want when same IID is found (if it was already echoed above) to pass over it and do nothing hope you understand now what i want to do.thanks for reply folks Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577325 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 I think PFMaBiSmAd is right and this would require a GROUP BY clause which groups the results based on the IID field but currently I cannot test this so you'll have to look it up yourself (unless someone else can?). Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577330 Share on other sites More sharing options...
Minase Posted June 29, 2008 Author Share Posted June 29, 2008 yes it do really works thanks for your help,btw how can i use multiple group by? thanks again Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577336 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 I don't know too much about it so untill someone posts some more informatin you should check out this Google search. http://www.google.co.uk/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-GB%3Aofficial&hs=JrJ&q=multiple+GROUP+BY&btnG=Search&meta= Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577337 Share on other sites More sharing options...
Minase Posted June 29, 2008 Author Share Posted June 29, 2008 thank you i did solve it with GROUP BY IID ORDER BY UID ASC thanks all for help Link to comment https://forums.phpfreaks.com/topic/112444-solved-group-items/#findComment-577340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.