Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A Little help with Code needed

Explorer ,
Nov 06, 2008 Nov 06, 2008
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;
TOPICS
Advanced techniques
444
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2008 Nov 06, 2008
newchickinCF wrote:
> I have alittle PHP snippet in a While loop and i am getting into problems while
> converting it

So what problem are you having?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008
do while stuff is troubling me, i visited livedocs to get that in something but i am getting unsuccessfull.

ere is my try:

<cfscript>
do
{
ratetotal = #ratetotal# + #showRate.rating#;
ratecount++;
}
while(#showrate.recordcount#);
</cfscript>
<cfset newrate = #ratetotal# / #ratecount#>

but that does seems to work either
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2008 Nov 06, 2008
see if this helps:

<cfif showrate.recordcount>
<cfset newrate = arraysum(showrate['rating']) / showrate.recordcount>
<cfelse>
<!--- do whatever you do if showraterecordcount is 0 --->
</cfif>

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 06, 2008 Nov 06, 2008
LATEST
newchickinCF wrote:
> do while stuff is troubling me, i visited livedocs to get that in something but
> i am getting unsuccessfull.
>

ColdFusion has two forms of this.

In its tag form this is done with an <cfloop condition=""> tag. But
this is closer to a "While" loop then a "Do-While" loop.
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_j-l_12.html

In its script form it has both the While and Do-While loops.
<cfscript>
while (condition) {
//stuff
}
</cfscript>
http://livedocs.adobe.com/coldfusion/8/htmldocs/CFScript_07.html

<cfscript>
do {
//stuff
} while (condition);
</cfscript>
http://livedocs.adobe.com/coldfusion/8/htmldocs/CFScript_08.html
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources