AE117 Posted January 7, 2011 Share Posted January 7, 2011 I have an array I would like to search that is being built from a data base as follows $result = mysql_query("SELECT id_one, id_two FROM accounts LIMIT 60"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("ID_ONE: %s ID_TWO: %s", $row[0], $row[1]); echo "<br>"; } What I would like to do is after the array is created echo out a certain row from that array. Soi if the array looks like this key id_one id_two 1 458 444 2 468 455 3 467 466 I can search the array for 468 and it would return 455 Thanks I will be posting back if I find any new information my self. Link to comment https://forums.phpfreaks.com/topic/223661-search-array/ Share on other sites More sharing options...
phpchamps Posted January 7, 2011 Share Posted January 7, 2011 Hops this helps : <?php $db = mysql_connect('localhost','root','') or die("Database error"); mysql_select_db('test', $db); $result = mysql_query("set names 'utf8'"); $query = "select * from test"; $result = mysql_query($query); $returnArr = array(); while($row = mysql_fetch_array($result)){ $returnArr[$row['id_1']] = $row['id_2']; } $searchArr = 100; // Enter the key to be searched if(array_key_exists($searchArr,$returnArr)){ // This will check the whether key exists or not echo "Available Value Is :". $returnArr[$searchArr]; }else{ echo "Key Doesnt Exists"; } ?> Link to comment https://forums.phpfreaks.com/topic/223661-search-array/#findComment-1156142 Share on other sites More sharing options...
AE117 Posted January 7, 2011 Author Share Posted January 7, 2011 Above did not work, I had to take this from a completely different approach. Thanks though. Link to comment https://forums.phpfreaks.com/topic/223661-search-array/#findComment-1156178 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.