Jump to content

Need help adding rows in a mysql database?


kpetsche20

Recommended Posts

I'm trying to get the total of $row['value']. This code just gives me a weird number.

 

?php

               

                $resultID = @mysql_query("SELECT * FROM `user_banking` WHERE `referral` = '$_SESSION[id]'", $linkID);
               
			for ($x= 0; $x < mysql_num_rows($resultID); $x++) {
                        $row = mysql_fetch_array($resultID);


				$cur_bal = "";
		 $cur_bal = $cur_bal + $row['value'];
                    
				echo $cur_bal;


		print "<tr><td width=\"192\" class=\"myaccount\">$$row[value]</td>
		<td width=\"193\" class=\"myaccount\">$row[from]</td>
		<td width=\"193\" class=\"myaccount\"> $row[referral]</td>

		</tr>\n";



                      
                }



?>

Link to comment
Share on other sites

 

 

I just noticed that you are using your variables as strings. make sure you declare your $cur_bal = 0; no quotes BEFORE you enter the for loop. otherwise it just clears the variable every time you run a iteration of the loop then echos the value... the output you are seeing makes perfect sense.

Link to comment
Share on other sites

Try This code:

 

<?php
$resultID = @mysql_query("SELECT * FROM `user_banking` WHERE `referral` = '$_SESSION[id]'", $linkID);

$cur_bal = 0;

for ($x= 0; $x < mysql_num_rows($resultID); $x++) {
$row = mysql_fetch_array($resultID);


$cur_bal += $row['value'];

echo $cur_bal;


print "<tr><td width=\"192\" class=\"myaccount\">$" .$row[value] ."</td>
		<td width=\"193\" class=\"myaccount\">" .$row[from] ."</td>
		<td width=\"193\" class=\"myaccount\"> " .$row[referral] ."</td>

		</tr>\n";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.