SkyRanger Posted November 23, 2006 Share Posted November 23, 2006 Ok, with a little help I got the combine 2 tables worked out, but now I have discovered a problem that I never thought of. I tried a number of things..ie limit but unfortionatly it will not work.Here is the code:[code]SELECT * FROM client, addserve WHERE client.username = addserve.username AND client.username = '$username' limit 1[/code]That will allow me to pull the info that is required out of client but there is a number of listing for $username in addserve that I want to display but when I remove the limit one it makes a new display for each entry from addserve which i don't want. I want 1 display from client but want to show all the entries for username from addserveex: [u]with limit 1 added[/u]Full Name: John SmithUsername: jsmithaddress: 123 my streetServices: Package 1[u]without limit 1 added[/u]Full Name: John SmithUsername: jsmithaddress: 123 my streetServices: Package 1Full Name: John SmithUsername: jsmithaddress: 123 my streetServices: Package 2Full Name: John SmithUsername: jsmithaddress: 123 my streetServices: Package 3etcWhat I want it to do is:Full Name: John Smith //output from clientUsername: jsmith //output from clientaddress: 123 my street //output from clientServices: Package 1,Package 2, Package 3 etc //output from addserveIs this possible? Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/ Share on other sites More sharing options...
trq Posted November 23, 2006 Share Posted November 23, 2006 You'll need to use a GROUP BY clause. Somthing like...[code]SELECT * FROM client, addserve WHERE client.username = addserve.username AND client.username = '$username' GROUP BY addserve.username[/code] Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/#findComment-129274 Share on other sites More sharing options...
SkyRanger Posted November 23, 2006 Author Share Posted November 23, 2006 [quote author=thorpe link=topic=116079.msg472770#msg472770 date=1164317308]You'll need to use a GROUP BY clause. Somthing like...[code]SELECT * FROM client, addserve WHERE client.username = addserve.username AND client.username = '$username' GROUP BY addserve.username[/code][/quote]Ok I did that but doesn't seem to work for me, not sure If i did something wrong:[code]SELECT * FROM client, addserve WHERE client.username = addserve.username AND client.username = '$username' GROUP BY addserve.username$wordnum = mysql_num_rows( $result );while( $row = mysql_fetch_array( $result ) ){echo $row['fullname']; //from client tableecho $row['address']; //from client tableecho $row['phone']; //from client tableecho $row['serv']; //from addserve tableecho "<br>"; //part of the serv output to put next serv on new line*Didn't want to put useless table code to loose what I need help on [/code]It is only showing 1 entry for serv and I need it to display all the entries for serv where it matches the username.It show right now:Fullname: John SmithAddress: 123 My StreetPhone: 555-555-5555Service: Package 1I need it to show all that but for Service:Service: Package 1, Package 2 etc Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/#findComment-129307 Share on other sites More sharing options...
SkyRanger Posted November 24, 2006 Author Share Posted November 24, 2006 ok, i even tried this[code]SELECT * FROM client INNER JOIN addserve ON client.username=addserve.usernameWHERE addserve.username = '$username' GROUP BY addserve.username[/code]Still no luck. I can get all the data to show that is required minus the stuff from the second table. It will only show 1 entry for username when there is more than 1 that needs to be displayed.Shows this:Fullname: John SmithAddress: 123 My StreetPhone: 555-555-5555Service: Package 1when I need this:Full Name: John Smith //output from clientUsername: jsmith //output from clientaddress: 123 my street //output from clientServices: Package 1, Package 2, Package 3 etc //output from addserve Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/#findComment-129388 Share on other sites More sharing options...
btherl Posted November 24, 2006 Share Posted November 24, 2006 That's tough to express in SQL. I think it's easier just to fetch all the rows without the GROUP BY, and merge them in PHP.GROUP BY is great when you want to find sums and counts, but when you're merging text data.. the rules for merging duplicate entries get messy. In this case you want to append all the packages together (the duplicate merging rule), while grouping by name, username and address. Just use php :) Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/#findComment-129421 Share on other sites More sharing options...
SkyRanger Posted November 24, 2006 Author Share Posted November 24, 2006 Yeah, that is what I ended up doing. Thanks Link to comment https://forums.phpfreaks.com/topic/28268-pulling-data-from-mysql-solved/#findComment-129434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.