EasyCFM.COM ColdFusion Forums / PHP to CFML / Converting PHP to Coldfusion

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Converting PHP to Coldfusion

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Caliber
11-14-2006 @ 10:51 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 106
Joined: Sep 2003

Hello All! OK maybe I went about my first post the wrong way. In my first post I included all of the code from the PHP page...I'm sorry for that. I have managed to convert most of the PHP code already, but there sections that are still giving me a problem. So I will post the parts I need help with. Thanx in Advanced!



      $query = mysql_query("SELECT buddylist FROM users WHERE username='$from' AND password='".$pwd."'");
      if(@mysql_num_rows($query) > 0) {
         $user_bl = mysql_fetch_assoc($query);
         $set_status = @mysql_query("UPDATE users SET is_online='".mysql_real_escape_string($_POST['away']+1)."', last_ping='".time()."' WHERE username='".mysql_real_escape_string($from)."'");

         $query = @mysql_query("SELECT message,sender FROM messages WHERE recipient='".mysql_real_escape_string($from)."'");
         header("Content-type: text/xml");
         print '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
         print "<main>\n<numMessages>";
         if(@mysql_num_rows($query) > 0) {
            print mysql_num_rows($query) . "</numMessages>\n";
            while ($row = @mysql_fetch_assoc($query)) {
               print "<message>\n";
               print '<from>'.$row['sender']."</from>\n";
               print '<data>'.rawurldecode($row['message'])."</data>\n";
               print "</message>\n";
            }
         } else {
            print "0</numMessages>\n";
         }

         $delete_new = @mysql_query("DELETE FROM messages WHERE recipient='$from'");

         print "<buddyList>\n";

         $query = @mysql_query("SELECT username,is_online FROM users WHERE username IN('".str_replace(",","','", $user_bl['buddylist'])."') ORDER BY username ASC");
         print "<numBuddies>".mysql_num_rows($query)."</numBuddies>\n";

         if(mysql_num_rows($query) > 0) {
            while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
               print '<user status="'.($row['is_online']==2 ? 'away' : ($row['is_online']==1 ? 'online' : 'offline')).'">'.$row['username'].'</user>'."\n";
            }
         }
        
         print "</buddyList>\n";
         print "</main>\n";
      } else {
            $set_status = @mysql_query("UPDATE users SET is_online='0', last_ping='".time()."' WHERE username='".mysql_real_escape_string($from)."'");
            print 'not_logged_in';
      }
      break;      


   case 'login':



no question is silly or stupid....its only silly and stupid when you don't ask!!!

Caliber
11-27-2006 @ 1:20 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 106
Joined: Sep 2003

Listen I successful converted the PHP code over to CF:p...Thanx for the help?.? Yeah!

no question is silly or stupid....its only silly and stupid when you don't ask!!!

phamtum
09-26-2007 @ 2:00 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 8
Joined: Feb 2004

Hi Caliber,

I was wondering if you can give me a hand with my php to coldfusion convertion?

<?php

// setting the directory to search for mp3 files
$dir = "mp3/";

// reading the directory and inserting the mp3 files in the playlist array
$playlist = array();
$fdir = opendir($dir);
while($i = readdir($fdir)) {
   // if a .mp3 string is found, add the file to the array
   if (strpos(strtolower($i),".mp3") !== false)
          $playlist[] = $i;
}
// close the directory
closedir($fdir);

sort($playlist);// make an alphabetical ordered list (if you don't want an ordered list, just comment this line)
shuffle($playlist);// make a randomized list (if you don't want a randomized list, just comment this line)

header("Content-type: text/xml");
// echoing the playlist to flash
echo "<player showDisplay=\"yes\" showPlaylist=\"yes\" autoStart=\"no\">\n";
for ($i=0; $i<sizeof($playlist); $i++) {
   // for the title it filters the directory and the .mp3 extension out
   $title = str_replace(".mp3","",$playlist[$i]);
   // clean filename (convert "_" into " ")
   $title = str_replace("_", " ", $title);
   echo "  <song path=\"$dir{$playlist[$i]}\" title=\"$title\" />";
}
echo "</player>";
?>

thanks in advance!!!


Website Designed and Developed by Pablo Varando.