Mardoxx Posted July 28, 2009 Share Posted July 28, 2009 id name 1 Adam 2 Bill <?php $id_list_array = array(1,2); foreach ($id_list_array as $id_number) { echo "$id_number<br />"; if ($row['id'] == $id_number) { echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>added\n"; break; } else { echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>notadded\n"; break; } } ?> It just outputs this: 2<!!!>Bill<!!!>notadded instead of 1<!!!>Adam<!!!>added 2<!!!>Bill<!!!>added any ideas why? thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/ Share on other sites More sharing options...
Mardoxx Posted July 28, 2009 Author Share Posted July 28, 2009 or if anyone can think of a more efficient way of doing it I would be very grateful! What ID is unique, and so are the ID's in the array I can't think of a way of mayching them up other than checking each new row against the whole array. anyone? Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885383 Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 what exactly are you trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885388 Share on other sites More sharing options...
abazoskib Posted July 28, 2009 Share Posted July 28, 2009 and what query are you running? perhaps you are pulling the result set in a way where Bill would show up as the first row returned. Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885390 Share on other sites More sharing options...
Mardoxx Posted July 28, 2009 Author Share Posted July 28, 2009 SELECT * FROM data there's a csv list of data that has been selected posted to the php file this is then exploded to an array. I want this php script to echo ALL the data but give a different output on the data that has an ID which is in the array. (also I want it done in one query if possible) Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885396 Share on other sites More sharing options...
papillonstudios Posted July 28, 2009 Share Posted July 28, 2009 could we see all the code for this file? Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885402 Share on other sites More sharing options...
.josh Posted July 28, 2009 Share Posted July 28, 2009 $ids = array(1,2,3); while($row = mysql_fetch_assoc($result)) { if (in_array($row['id'],$ids)) { // id is in $ids, do something } else { // id is not in $ids, do something } } Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885403 Share on other sites More sharing options...
papillonstudios Posted July 28, 2009 Share Posted July 28, 2009 This should work <?php $id_array = array(1,2); while($row = mysql_fetch_assoc($result)) { if (in_array($row['id'],$id_array)) { echo $row['id'] . '<!!!>' . $row['name'] .'<!!!>added<br />'; } else { echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>notadded<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885415 Share on other sites More sharing options...
Mardoxx Posted July 28, 2009 Author Share Posted July 28, 2009 Crayon Violent, gfadmin Works great, thank you very much!!!! Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885434 Share on other sites More sharing options...
papillonstudios Posted July 29, 2009 Share Posted July 29, 2009 no problem Quote Link to comment https://forums.phpfreaks.com/topic/167867-solved-can-someone-have-a-look-at-this-for-me-please/#findComment-885652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.