huntr77 Posted January 17, 2011 Share Posted January 17, 2011 Hi, I'm hoping someone can help me with a simply array problem. I have a table with two columns: "ID" and "Name" and 100 Names. I also have an array called $myIDList containing 10 IDs. I want to display 10 Names from the table that correspond with the IDs from my array. Originally, I tried to implode the array, adding commas and inserted into my MySQL query using: $myQuery = "SELECT ID, Name FROM namesTable WHERE ID IN ($myImplodedIDList)"; The problem was that duplicated names (i.e. the same Name, but assiged to different IDs) would only be displayed once. So now I'm trying to use the original array to loop through a second array and display Names where the ID matches an ID from my first array. I have succesffuly listed the table like this: $myQuery = "SELECT ID, Name FROM myTable ORDER BY ID"; $myResult = mysql_query($myQuery) or die(mysql_error()); while($row=mysql_fetch_array($myResult)) { echo $row['ID']; echo $row['Name']; } But I want to do something like: while($row=mysql_fetch_array($myResult)) { while $row['ID'] = $myIDList { echo $row['Name'] } } Can someone shed some light onto this for me please? Thank you! Bryan Link to comment https://forums.phpfreaks.com/topic/224686-how-to-use-one-array-to-display-items-from-a-second-array/ Share on other sites More sharing options...
Pikachu2000 Posted January 17, 2011 Share Posted January 17, 2011 Are the actual IDs in the array you tried to implode, perhaps as the index for each name value? Link to comment https://forums.phpfreaks.com/topic/224686-how-to-use-one-array-to-display-items-from-a-second-array/#findComment-1160893 Share on other sites More sharing options...
huntr77 Posted January 17, 2011 Author Share Posted January 17, 2011 good question but no, they're from a different table. i know there might be a way to link them but i just need something quick and dirty but i'm not having much luck. any help appreciated ... Link to comment https://forums.phpfreaks.com/topic/224686-how-to-use-one-array-to-display-items-from-a-second-array/#findComment-1160899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.