| | |
HELP PHP w/SQL Code HELP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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:
Problem here is that it is not adding all the rows together and then getitng the price but instead its just avraging 1 row.
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)
$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.
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.
[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.
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.
______________________________________________
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.
![]() |
Similar Threads
- Problem with php and SQL (PHP)
- how to do conenction between php and my sql (PHP)
- changing my php sql code to oracle (MySQL)
- PHP/SQL query help (PHP)
- Saving Code in PHP (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Help to create a unique forum
- Next Thread: help on extractin from vbulletin
| Thread Tools | Search this Thread |
# 5.2.10 action address apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display dissertation domain dynamic echo echo$_get[x]changingitintovariable... email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image images include insert ip javascript joomla legislation limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop open paypal pdf persist php popup problem query radio random record recursion remote script search server sessions sms sockets source space sql syntax system table tutorial update upload url validator variable video web youtube





