EasyCFM.COM ColdFusion Forums / PHP to CFML / Help Coding to CFM

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Help Coding to CFM

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

gavy
11-06-2008 @ 10:20 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 72
Joined: Feb 2005

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
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1149
Joined: Jan 2007

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


Website Designed and Developed by Pablo Varando.