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.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!
how to make more than one variable out of multiple SQL info
Moderator: General Moderators
- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
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!
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!
- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
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.
does that make sense?
Code: Select all
//instead of this
$totalSum+=number_format($total_cart, 2, '.', '');
echo $totalSum;
//do this
$totalSum+=$total_cart;
echo number_format($totalSum,2,'.','');
Last edited by maliskoleather on Thu Sep 20, 2007 1:14 pm, edited 1 time in total.
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?
is somethin like this ok?
Code: Select all
$totalSum=+$total_cart;
$grand_total = number_format($totalSum,2,'.','');- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
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:
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.- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
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
they're both semeing identical and both outputting the same way.
I can live with it as long as the decimal is there
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
- maliskoleather
- Forum Contributor
- Posts: 155
- Joined: Tue May 15, 2007 2:19 am
- Contact:
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.
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,'.','');