RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1400 | Replies: 4
Reply
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Help HELP PHP w/SQL Code HELP

  #1  
Jun 29th, 2005
Hi All
I need help and i am new to php so bare wih me
what i m tryin 2 do is that add poduct shipping handeling togther to get an avraged rate so this is the part of code Troubling me:

$nrow = mysql_num_rows($result);
if ($Vh4 == "VH4")
{
	for ($i=0;$i<$nrow;$i++);
	{
		$row = mysql_fetch_array($result);
		extract ($row);
		$Total = $Total + $VH4 + $UD4 + $Handling;
	}

}
else
{
	echo "LOL<BR><BR>";
}

$Total = $Total / $nrow; 
echo "<br>$Total<br>";


Problem here is that it is not adding all the rows together and then getitng the price but instead its just avraging 1 row.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: HELP PHP w/SQL Code HELP

  #2  
Jun 29th, 2005
I do not understand how it would not be looping $nrow times. Please add echo() statements after most every line to output debugging information. For example:
[PHP]
if (!$result) {
echo "<br />ERROR! result is false.";
}
$nrow = mysql_num_rows($result);
echo "<br />nrow: ".$nrow;
if ($Vh4 == "VH4")
{
echo "<br />Starting loop";
for ($i=0;$i<$nrow;$i++);
{
echo "<hr />i: ".$i;
$row = mysql_fetch_array($result);
if (!$row) {
echo "<br />ERROR! row is false.";
}

extract ($row);
echo "<br />VH4: ".$VH4;
echo "<br />UD4: ".$UD4;
echo "<br />Handling: ".$Handling;
$Total = $Total + $VH4 + $UD4 + $Handling;
echo "<br />Total: ".$Total;
}
}
else
{
echo "LOL<BR><BR>";
}
echo "<hr />nrow: ".$nrow;
echo "<br />Total: ".$Total;
$Total = $Total / $nrow;
echo "<br>$Total<br>"; [/PHP]
See if this does not show you where the problem is. Let us know.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Solution Re: HELP PHP w/SQL Code HELP

  #3  
Jun 30th, 2005
Hi I tried it and it didn't work here is the results
______________________________________________
nrow: 2
Starting loop
--------------------------------------------------------------------------
i: 2
VH4: 100.00
UD4: 103.00
Handling: 25.00
Total: 228
--------------------------------------------------------------------------
nrow: 2
Total: 228
114
_______________________________________________

As you see the second part should have been reped 2 time with different figures.
so now i am comfused about why it is not looping.
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: HELP PHP w/SQL Code HELP

  #4  
Jun 30th, 2005
AHA!!! Remove the semicolon at the end of this line:
[PHP]
for ($i=0;$i<$nrow;$i++);
[/PHP]
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Re: HELP PHP w/SQL Code HELP

  #5  
Jul 1st, 2005
Thanks that helped a lot and because of this hint i was able to expand the program even more...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC