smith.james0 Posted July 20, 2006 Share Posted July 20, 2006 I have searched the forum and the web but I am not getting to far.I need to load all the ip addesses (one column) out of my db into a single array so I can search it.I have found how to load it multiple arrays but this is no good.Can anyone point me in the right direction?Many thanks James Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/ Share on other sites More sharing options...
cmgmyr Posted July 20, 2006 Share Posted July 20, 2006 To load them in a single array try...[code]<?php //Find total number of ips $query = "SELECT ip FROM table"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $count = mysql_numrows($result); $ips = array(); $x = 0; while ($x < $count): $ipaddress = mysql_result($result, $x, 'ipaddress'); $ips[$x] = $ipaddress; $x++; endwhile;?>[/code]Is that what you were looking for?-Chris Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61303 Share on other sites More sharing options...
ryanlwh Posted July 20, 2006 Share Posted July 20, 2006 can you search using sql queries?? then you don't even need to load an array Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61306 Share on other sites More sharing options...
HeyRay2 Posted July 20, 2006 Share Posted July 20, 2006 We need a little more information before we can suggest the best coding method.What is your goal with searching the IP addresses?What is the purpose of the script?How are the tables in your database structured? Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61310 Share on other sites More sharing options...
Barand Posted July 20, 2006 Share Posted July 20, 2006 mysql_fetch row() is more efficient than mysq_result().[code]<?php $query = "SELECT ip FROM table"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $ips = array(); while ($row = mysql_fetch_row($result)) { $ips[] = $row[0]; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61321 Share on other sites More sharing options...
smith.james0 Posted July 20, 2006 Author Share Posted July 20, 2006 I am loading all the IP addresses into the array then searching the array for IP addresses which are currently online. Then change the font colour of those online. Part of the admin panel i am making. Part of the reason is to learn more about arrays as i haven't used them yet.James Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61333 Share on other sites More sharing options...
boralyl Posted July 21, 2006 Share Posted July 21, 2006 Well loading them into an array is as simple as[code]<?php$find = "SELECT ip FROM table";$result = mysql_query($find);$ips = array();while($row = mysql_fetch_assoc()){ $ips[] = $row['ip'];}//View the ipsprint_r($ips);?>[/code]sorry Barand I didn't notice you wrote almost the exact same code Quote Link to comment https://forums.phpfreaks.com/topic/15193-loading-column-into-signle-array-help/#findComment-61452 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.