Dethman Posted March 23, 2009 Share Posted March 23, 2009 Ok I had someone that was helping me on this but he dropped offline so you guys are my best bet. Ok I have a table called Contacts in the SQL now there are 2 fields ContactID and OwnerID I need to grab all of the ContactID's and throw them at an sql query that gets the username assosiated with that id from a different sql table and then echo's each username ASC How would I do that? ContactID would be used like this SELECT `Username` FROM `PlayerInfo` WHERE `id` = '{ContactID Goes Here}' Any and all help would be apreciated, Dethman Link to comment https://forums.phpfreaks.com/topic/150688-contacts-list-needing-help/ Share on other sites More sharing options...
syed Posted March 23, 2009 Share Posted March 23, 2009 If you mean you want to join two tables, you will need to have a primary key in one table and the same primary key should be the foreign key in the other table. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/150688-contacts-list-needing-help/#findComment-791612 Share on other sites More sharing options...
Dethman Posted March 23, 2009 Author Share Posted March 23, 2009 Ok ill draw something out // Say the User has 5 Contacts.. Here are there id's and a way to call them $select="SELECT * FROM `Contacts` WHERE `OwnerID` = '".$_SESSION['id']."' ORDER BY `id` ASC"; $res=mysql_query($select) or die("Unable to Connect 1.<BR/>".mysql_error()); $row=mysql_fetch_array(); $cid=$row['ContactID']; $cid_1 = $row['ContactID']; // Really 1 $cid_2 = $row['ContactID']; // Really 2 $cid_3 = $row['ContactID']; // Really 3 $cid_4 = $row['ContactID']; // Really 4 $cid_5 = $row['ContactID']; // Really 5 //Now I need to take each of those id's and do this to them. $query="SELECT `Username` FROM `PlayerInfo` WHERE `id` = '".$cid_1."'"; $res=mysql_query($query) or die("Error Message".mysql_error()); $row=mysql_fetch_array($res); echo $row['Username']; //The User can have up to 1-100,000 Contacts I need to make it automated Does that make any since? Link to comment https://forums.phpfreaks.com/topic/150688-contacts-list-needing-help/#findComment-791617 Share on other sites More sharing options...
FaT3oYCG Posted March 23, 2009 Share Posted March 23, 2009 maybe try this $select="SELECT * FROM `Contacts` WHERE `OwnerID` = '".$_SESSION['id']."' ORDER BY `id` ASC"; $res=mysql_query($select) or die("Unable to Connect 1.<BR/>".mysql_error()); while($row=mysql_fetch_array($res)) { $query="SELECT `Username` FROM `PlayerInfo` WHERE `id` = '".$row['id']."'"; $resa=mysql_query($query) or die("Error Message".mysql_error()); $rowa=mysql_fetch_array($resa); echo $rowa['Username']; } Link to comment https://forums.phpfreaks.com/topic/150688-contacts-list-needing-help/#findComment-791622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.