Ive modified the code a little bit but still it returns $totalunvepayment to zero:Whats wrong with this code.?
$query_recunvesummary="SELECT * FROM paymentsummary WHERE username='".mysql_real_escape_string($_SESSION['MM_Username'])."' AND paymentmode='".mysql_real_escape_string($modeofpay)."' AND foryear='".mysql_real_escape_string($_SESSION['MM_yearlynow'])."' AND initialstatus='".mysql_real_escape_string($_SESSION['MM_paymentstatus'])."'";
$recunvesummary = mysql_query($query_recunvesummary, $enamysqldb) or die(mysql_error());
$row_recunvesummary = mysql_fetch_assoc($recunvesummary);
$totalRows_recunvesummary = mysql_num_rows($recunvesummary);
$totalunvepayment=0;
while($row = mysql_fetch_array($recunvesummary)){
$totalunvepayment = $totalunvepayment + $row['amountpaid'];
}
$_SESSION['MM_totalunvepayment']=$totalunvepayment;
When i echo the sql statement its echos (Resource ID #9) what does this mean.?
Pls help.
God bless on this mother earth.
Are you missing the connect statement, like:
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
And why are you fetching data into an associative array via mysql_fetch_assoc() and then using mysql_fetch_array()? I think you can only fetch the data once....
Here's what I do with great success:
// function do_sql executes the specified statements, handles error,
// and returns the resource by reference.
function do_sql($db, &$resource, $err_msg, $qstring) {
//print "<p>$qstring</p>\n";
$resource = mysql_query($qstring, $db)
or die ($err_msg.": ".mysql_error());
}
// Database preparation
$datasetobj = mysql_connect("localhost", "username", "password")
or die ("Unable to connect to database");
mysql_select_db("db_name", $dataestobj)
or die ("Unable to select database");
// Query operation
do_sql($datasetobj, $result, "Couldn't fetch data",
"SELECT * FROM my_table
WHERE my_column='5'");
$my_row_count = mysql_num_rows($result);
//print("<pre>Rows returned: $my_row_count</pre>\n");
// Result handling
if ($my_row_count>0)
{
while ($my_row = mysql_fetch_array($result))
{
//print("<pre>"); print_r($my_row); print("</pre>\n");
.
.
.
}
}
You can uncomment the print statement in do_sql() to see the query that's being processed. And you can uncomment the prints in the fetch loop to see the data that's returned. These debug prints may show up in weird places, but you'll at least be able to see what's going on. And you can comment them out or delete them for 'production'.
Don't ask how many months it took me to get php/mysql to work reliably. And don't ask how many
years it took before I realized I should write do_sql(), and to let PHP put the result into an associate array (with both numeric indices and column-name indices).
With that little bit of code above, I can whip up mysql-based web pages lickety-split. Each query gets a unique error message so I know where the failure is.