Topic: Help Coding to CFM


gavy    -- 11-06-2008 @ 10:20 AM
  I have alittle PHP snippet in a While loop and i am getting into problems while converting it

$sql = "select rating from r_ratings where iid = $iid";

$result3 = mysql_query($sql ,$db);

if ($myrow2 = mysql_fetch_array($result3)) {

do {
$ratetotal = $ratetotal + $myrow2["rating"];
$ratecount++;
} while ($myrow2 = mysql_fetch_array($result3));

}

$newrate = $ratetotal / $ratecount;

<< << ArrowHead >> >>

<cf_bitterhead>
I Changed My Signature Coldfusion + Fusebox Started
</cf_bitterhead>


louissto56    -- 12-26-2008 @ 10:59 PM
  Wow this is an old one. For the fun of it, Ill give it a go.

<cfquery name="q">
select rating from r_ratings where iid = #iid#
</cfquery>

<cfif q.recordcount>
<cfset ratetotal = 0>
<cfset ratecount = 0>

<cfloop query="q">
<cfset ratetotal += q.rating>
<cfset ratecount++>
</cfloop>

<cfset newrate = ratetotal / ratecount>
</cfif>

-----------------------------
www.MyBizList.com.au - QLD Business Directory and rent-a-site


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=27&Topic=13861