943,801 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1821
  • PHP RSS
Jun 29th, 2005
0

HELP PHP w/SQL Code HELP

Expand Post »
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:

PHP Syntax (Toggle Plain Text)
  1. $nrow = mysql_num_rows($result);
  2. if ($Vh4 == "VH4")
  3. {
  4. for ($i=0;$i<$nrow;$i++);
  5. {
  6. $row = mysql_fetch_array($result);
  7. extract ($row);
  8. $Total = $Total + $VH4 + $UD4 + $Handling;
  9. }
  10.  
  11. }
  12. else
  13. {
  14. echo "LOL<BR><BR>";
  15. }
  16.  
  17. $Total = $Total / $nrow;
  18. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
ashneet is offline Offline
147 posts
since Jun 2005
Jun 29th, 2005
0

Re: HELP PHP w/SQL Code HELP

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.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 30th, 2005
0

Re: HELP PHP w/SQL Code HELP

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.
Reputation Points: 10
Solved Threads: 1
Junior Poster
ashneet is offline Offline
147 posts
since Jun 2005
Jun 30th, 2005
0

Re: HELP PHP w/SQL Code HELP

AHA!!! Remove the semicolon at the end of this line:
[PHP]
for ($i=0;$i<$nrow;$i++);
[/PHP]
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jul 1st, 2005
0

Re: HELP PHP w/SQL Code HELP

Thanks that helped a lot and because of this hint i was able to expand the program even more...
Reputation Points: 10
Solved Threads: 1
Junior Poster
ashneet is offline Offline
147 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help to create a unique forum
Next Thread in PHP Forum Timeline: help on extractin from vbulletin





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC