Jump to content

Archived

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

ddm

Yahoo Online Status

Recommended Posts

Hi All, I am a php newbie, I am trying to create a site where users will register and enter their yahoo id. I want the users who are online on their yahoo messengers to show first on the list of users.

Here is the code that will show if they are online or offline on yahoo.

[code]

<?php

  // Request Profile Info
  $result = @mysql_query("SELECT * FROM
profile");
  if (!$result) {
    echo("<p>Error performing query: " . mysql_error() .
"</p>");
    exit();
  }
  // Display the Content of the profile Table
    while ( $row = mysql_fetch_array($result) ) {


$PrimaryYID = $row['PrimaryYID'];


echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"3\" width=\"400\">";


    $url = "http://mail.opi.yahoo.com/online?u=".$PrimaryYID."&m=t&t=0";
    $handle = fopen ("$url", "r");
    $contents = "";
    do {
    $data = fread($handle, 10000);
    if (strlen($data) == 0) {
    break;
    }
    $contents .= $data;
    } while(true);
    fclose ($handle);
    if ((strpos(strtoupper($contents),"NOT ONLINE") ?
    strpos(strtoupper($contents),"NOT ONLINE")+1 : 0)>0)
    {
    $imgStatus = "<img src='ym/offline.gif' ALT='OFFLINE' border='0'>";
    }
    else
    {
    $imgStatus = "<img src='ym/online.gif' ALT='ONLINE' border='0'>";}



    echo "<tr bgcolor=\"#eeeeee\"><td><b><a href=\"ymsgr:sendIM?$PrimaryYID\">$PrimaryYID</a></b></td><td align=\"center\"><a href=\"ymsgr:sendIM?$PrimaryYID\"> $imgStatus </a></td></tr>";
}

echo "</table>";
?>

[/code]

I dont know how I can make it that those who are online on their yahoo messenger to show first on the list. Please help me.

Thanks in advance.

Share this post


Link to post
Share on other sites
[!--quoteo(post=354491:date=Mar 13 2006, 02:13 PM:name=ddmluvdlm)--][div class=\'quotetop\']QUOTE(ddmluvdlm @ Mar 13 2006, 02:13 PM) [snapback]354491[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi All, I am a php newbie, I am trying to create a site where users will register and enter their yahoo id. I want the users who are online on their yahoo messengers to show first on the list of users.
[/quote]

Your database has no idea if people are logged into yahoo or not. So your while loop which processes the database results can't be changed to sort by Yahoo logged in status.

What you need to do is to use the while loop to populate a new array which stores the database row, a 1 or a 0 to indicate Yahoo Logged in status and maybe their username as well.

You can then sort this array by logged in status, and username.

Finally you can walk through this array to print out the results. This would allow you to show all the logged in users first (listing them alphabetically), then all the other users (again alphabetically).

J

Share this post


Link to post
Share on other sites

×

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.