Jump to content

list entries by surname only if more than one exists in DB


jasonc

Recommended Posts

i wish to list entries where one of the fields is repeated elsewhere in the DB

 

say i want to list all the surnames of people with the name 'smith' but only if their is more than one all the single 'smiths' are not used for this.

 

the field is as you would expect,  'surname'

 

what query should i use to obtain these records?

 

 

Link to comment
Share on other sites

i use this to display the results but only get one from each 'group' not all in each group where there are doubles or repeats entries of the same surname.

 

i also used phpmyadmin and used the query there and got the same results, just a few of them when they is like 4 or 5  in most of the groups of 'surnames' (l_name)

 

for ($i = 0; $i < mysql_num_rows($members); $i++) {
?><br>f_name: <?=mysql_result($members, $i, "f_name");?> l_name: <?=mysql_result($members, $i, "l_name");?>
<? } ?>

Link to comment
Share on other sites

ok that worked

 

thanks

 

i wish to display then as follows

 

to the left is the surname and to the right is the first names.

 

surname1

                  firstname1

                  firstname2

                  firstname3

---------------------------

surname2

                  firstname1

                  firstname2

---------------------------

 

 

and so on...

 

 

but my code does not work  please help

 

<?

$members = mysql_query("SELECT * FROM `table` WHERE `l_name` IN (SELECT `l_name` FROM `table` GROUP BY `l_name` HAVING COUNT(*) > 1 ) ORDER BY `l_name`") or die(mysql_error());

for ($i = 0; $i < mysql_num_rows($members ); $i++) {

?><div align="left">Surname: <?=mysql_result($members , $i, "theip");?></div><br><?

while (mysql_result($members , $i, "l_name") != mysql_result($members , $i + 1, "l_name")) { ?>

<div =align="right"><?=mysql_result($members , $i, "f_name");?></div><?

$i++;

} ?><hr>

<?

$i--;

} ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.