Jump to content

Recommended Posts

Hey Guys.

 

Long time no speak to you all. I hope everyone is well.  OK so I have a search page which searches through a list of members.  Works great and here is the code for that.....

 

mysql_select_db($database_dbcon, $dbcon);$query_allClients = "SELECT userid, fname, sname, uad1, upost, utoken FROM `user` WHERE (branchid=".$_SESSION['cBranch']." AND permid!=".intval(99)." AND permid!=".intval(4).")  AND  statusid!='".intval(7)."' AND ( lfname LIKE '%$searchfld%' ORlsname LIKE '%$searchfld%' OR fname LIKE '%$searchfld%' OR sname LIKE '%$searchfld%' OR uad1 LIKE '%$searchfld%' OR uad2 LIKE '%$searchfld%' ORuarea LIKE '%$searchfld%' ORupost LIKE '%$searchfld%') ";$query_limit_allClients = sprintf("%s LIMIT %d, %d", $query_allClients, $startRow_allClients, $maxRows_allClients);$allClients = mysql_query($query_limit_allClients, $dbcon) or die(mysql_error());$row_allClients = mysql_fetch_assoc($allClients); do{echo $row_allClients['fname'].' '.$row_allClients['sname'].'            '.$row_allClients['upost'] .'           '.$row_allClients['uad1'];  } while($row_allClients = mysql_fetch_assoc($allClients));    

 

 

I have now added the ability to have multiple addresses assigned to one member.  To do this I have move the forename and the surname of the (landlord) over to a landlord table.  When I add a landlord I add the forename and surname to that table and I then add their home address to the users table with a extra field call ishome = '1' else ishome ='0'

 

I have also added the landlordid field to the user table so I can find any address a particular landlord owns.

 

Tables

 

landlord                                 user

landlordid                               userid

lfname                                    ishome

lsname                                   landlordid

                                              fname

                                              sname

 

Now when I search for a postcode the original search query still works great.  The only thing I want to change is formatting of how it looks.  So currently it brings back

 

user 1                    pr7ygf            64 some street name

user 2                   pr75tf             3 some other street name

user 3                   pr74rt             5 awesome street

etc

 

 

what I want is for it to effectively group the search results under the landlord each address belongs to, so for example.......

 

landlord 1

     user1              pr7ygf            64 some street name

     

 

landlord 2

     user 2           pr75tf              3 some other street name

     user 3           pr74rt             5 awesome street  

 

 

 

 

 

Ive tried to change the query to whats below however i'm sure sure of how to displace the formatted data

 

 

SELECT user.userid, user.fname, user.sname, user.uad1, user.upost, user.utoken, landlord.lfname, landlord.lsname FROM `user` INNER JOIN landlord ON user.landlordid = landlord.landlordid  WHERE (user.branchid=".$_SESSION['cBranch']." AND user.permid!=".intval(99)." AND user.permid!=".intval(4).")  AND  user.statusid!='".intval(7)."' AND (user.fname LIKE '%$searchfld%' OR user.sname LIKE '%$searchfld%' OR user.uad1 LIKE '%$searchfld%' OR user.uad2 LIKE '%$searchfld%' ORuser.uarea LIKE '%$searchfld%' ORuser.upost LIKE '%$searchfld%') 
 
 

 

 

Link to comment
https://forums.phpfreaks.com/topic/296395-group-search-results-by-landlord/
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.