EasyCFM.COM ColdFusion Forums / PHP to CFML / PHP->CFM fairly simple i think

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: PHP->CFM fairly simple i think

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

billybrag
03-29-2007 @ 5:40 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 163
Joined: Feb 2006

Could anyone convert this for me please

I cant get the if statement bit working


function compareCards($id_player, $id_comp, $attribute )
     {
     //compare the attribute for the given cards
     
     
          $player_sql = "SELECT $attribute
               FROM trump_cards
               WHERE card_id = '$id_player'";
          $player_result = dbQuery($player_sql);
          $player_row    = dbFetchAssoc($player_result);
     
     
          $comp_sql = "SELECT $attribute
               FROM trump_cards
               WHERE card_id = '$id_comp'";
          $comp_result = dbQuery($comp_sql);
          $comp_row    = dbFetchAssoc($comp_result);
          
          
          if($comp_row[$attribute] < $player_row[$attribute])
               {
                    //polayer wins
                    $trump = 1;
               }
          elseif($comp_row[$attribute]
>
$player_row[$attribute])
               {
                    //player loses
                    $trump = 0;
               }
          else
               {
                    //draw
                    $trump = 2;
               }
          
          return $trump;
     }

Webmaster
03-29-2007 @ 5:48 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

you mention you could not get the if statement working... what did you get working.. care to show what you have done so far?

I mean dont get me wrong; we are here to help.. but asking someone to do it for you will more then likely get you a: "How much are you paying me" response.

Post what you have so far and we'll help along the way for you to do it and learn from it.

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

billybrag
03-29-2007 @ 5:56 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 163
Joined: Feb 2006

this is what i tried,


<!--- ================================================================= --->
     <!--- compareCards --->
     <!--- ================================================================= --->     
     <cffunction name="compareCards"
               access="public"
               returntype="numeric"
               output="false">

               
          <!--- Function Arguments --->                         
               <cfargument name="id_player" type="numeric" required="yes" hint="PlayerId Value" />
               <cfargument name="id_comp" type="numeric" required="yes" hint="Computer Id Value" />
               <cfargument name="id_attribute" type="string" required="yes" hint="Attribute name" />
               
               
           <!--- get stuff from the db --->
          <cfquery name="playerCard" datasource="cfcms">
               SELECT #arguments.id_attribute#
               FROM trump_cards
               WHERE card_id = #arguments.id_comp#
            </cfquery>
          
          <cfquery name="compCard" datasource="cfcms">
               SELECT #arguments.id_attribute#
               FROM trump_cards
               WHERE card_id = #arguments.id_comp#
            </cfquery>
          
          <cfset attribute ="#arguments.id_attribute#">
          
          <cfif #compCard.attribute# LT #playerCard.attribute# >
               
               <cfset trump = 1>
          
          <cfelseif #compCard.attribute# GT #playerCard.attribute# >
               
               <cfset trump = 0>
          
          <cfelse>
               
               <cfset trump = 2>
          </cfif>
          <!--- If successfull return 1 else return 0--->
          
          <cfreturn trump />
     </cffunction>
     
     <!--- ================================================================= --->



like i said its the if statements that dont work as i cant recreate this bit...
if($comp_row[$attribute] < $player_row[$attribute])


Thanks
Mike Sharp

www.organiclinker.com


Website Designed and Developed by Pablo Varando.