Page 2 of 2
Posted: Thu Sep 20, 2007 10:44 am
by maliskoleather
jramaro wrote:ahh i see ! ... thanks
exhausting the while loop, that's because i havent used while loops enough and so they're still unfamiliar , so i make them syntax and formatting mistakes.
Thanks for your help, I'm gonna go and see if i cant break it now
I need to add more records to make sure its adding them up
Thanks!
its not so much the while loop that was your issue, as it was the mysql_fetch_array. every time you call that (or mysql_fetch_row, or any other resource handler) it moves the pointer forward one resultset. therefore, you would need to make a second query after the first while loop to use on the second while loop... but thats just excess code and a waste of memory, so its just easier and better to do as much as possible in one loop.
Posted: Thu Sep 20, 2007 10:52 am
by aceconcepts
Can you post the code your using and what exatly you hope to achieve.
Posted: Thu Sep 20, 2007 12:45 pm
by jramaro
ah thanks
well that was pretty cool .
and I got everything working now and it all seems to be pretty good.
I had a slight problem but thats because i was shifting code around in a restructuring frenzy and forgot to put the long code in the
start and end { } curly brackets.
but i pieced it all back together and included what you showed me with what i had and now its all workin.
The only thing is that the Grand Total of the sum of al lthe $total_carts is just like 7791 for example.
its not doing the 7,791 .00
i tried a regular number_format($total_cart,2);
but that made it come out like = 7 (excluding al lthe rest of the numbers) dunno why .
You guys been a big help though , I appreciate it thanks!

Posted: Thu Sep 20, 2007 12:50 pm
by maliskoleather
the format not working is because you're adding the format to another format (both are strings) and php is converting them to an integer when you do the += on it.
Code: Select all
//instead of this
$totalSum+=number_format($total_cart, 2, '.', '');
echo $totalSum;
//do this
$totalSum+=$total_cart;
echo number_format($totalSum,2,'.','');
does that make sense?
Posted: Thu Sep 20, 2007 1:02 pm
by jramaro
yeah it makes sense, but if i dont want to echo it right then , can i make it into variable to use other places except that echo ?
is somethin like this ok?
Code: Select all
$totalSum=+$total_cart;
$grand_total = number_format($totalSum,2,'.','');
Posted: Thu Sep 20, 2007 1:03 pm
by maliskoleather
yeah, that would work fine, assuming you dont try to add another integer to it

Posted: Thu Sep 20, 2007 1:08 pm
by jramaro
oh , thats only showing the last records total
is there any way to have it add them all up , but yet not have to echo it out like that?
and i noticed the way you posted:
Code: Select all
$totalSum=+$total_cart;
echo number_format($totalSum,2,'.','');
Code: Select all
thats only echoing out the last instance of $total
not adding them together.
Posted: Thu Sep 20, 2007 1:14 pm
by maliskoleather
errr.. typo. += not =+
Posted: Thu Sep 20, 2007 1:25 pm
by jramaro
lol , oh
yeah that works but its essentially the same thing as the other code now that i look closer at it.
They're both doing the same thing. they format the decimal point but they dont include a comma.
so example number is like (with dollar sign) : $ 3875.50
the two codes from before and the one you just gave are pretty much the same i think.
here they are
Code: Select all
$grand_total = $totalSum+=number_format($total_cart, 2, '.', '');
$totalSum+=$total_cart;
$grand_total = number_format($totalSum,2,'.','');
they're both semeing identical and both outputting the same way.
I can live with it as long as the decimal is there
Posted: Thu Sep 20, 2007 2:27 pm
by maliskoleather
technically their different, but it has to do with the data types.
essentially the output the same stuff... its just better practice to only format it right before you echo the string.
as for the comma, thats the last parameter in the number_format() function.
Code: Select all
//with comma
echo number_format($totalSum,2,'.',',');
//without
echo number_format($totalSum,2,'.','');
Posted: Thu Sep 20, 2007 3:12 pm
by jramaro
cool thank you.
I knew of number_format()
but not of the manual formating .
It's working now. and number example: $ 3,972.00
Thanks for all the help today
