Jump to content

help very much appreciated with some array stuff i cant do...


crashgordon

Recommended Posts

im trying to filter and create a new array from another array, that has been returned from a my sql request

this is what the original array looks likes.

 

id  reqTo    reqFrom  status

 

3    simon    john      1

4    kathy    simon    1

5    dave    peter      1

6    mikey    kathy      1

 

if the user is logged in and is kath i would like to create a new array that has only kaths contacts in and only one field or column called contacts for example...

 

 

<?

$user = $session->username;

$q = "SELECT * FROM contacts WHERE (reqFrom = '$user' OR reqTo = '$user') AND status = 1 ORDER BY reqTo ASC";

$result = $database->query($q);

 

function GCFrom($var){

return is_array($var) && $var['reqFrom'] === "$user";

  }

if(mysql_num_rows($result) == 0)

{

echo "<br/><span class='SmlB'>   $user, you have no contacts.....</span>";

}

else

 

{

while($conts = mysql_fetch_array($result))

{

 

        print_r(array_filter($conts,GCFrom));

 

}

}

 

?>

 

i made a very poor start, my idea was to filter each column for kaths contacts and create an new array from the two filtered arrays but i cant even get the filter to work lol and that's even before i try and make the new array work, so any help  and advice would be very much appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.