Jump to content

[SOLVED] Group Items


Minase

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.