Jump to content

Loading column into signle array help


smith.james0

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 ips
print_r($ips);
?>
[/code]

sorry Barand I didn't notice you wrote almost the exact same code
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.