Jump to content


Photo

Adding Values


  • Please log in to reply
22 replies to this topic

#21 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 January 2006 - 05:34 AM

This is starting to get a little ridiculous -- you're using the column names from the first record of the result set, but throwing out the actual data. That is _exactly_ the call to mysql_assoc() that we're talking about. You're also missing the close TR for the heading row. My suggestion: simply run that foreach again, and spit of the _values_ for that row, and then start the while loop. Second, WRT TRUNCATE(), it _does_ give you two decimal places, as promised. Maybe you want the ROUND() function instead.

BTW, you've asked about 10 separate questions in a single thread -- perhaps you should take the time to try and figure some of this out on your own time first to see how much you can get resolved in advance. All of the advice & suggestions you need to complete your task have been laid out already in this thread. Good luck.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#22 helpmeplease2

helpmeplease2
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts

Posted 06 January 2006 - 02:55 PM

I'm sorry if I've asked too many questions, I really new to PHP. I placed:

$results=mysql_query("SELECT * FROM customers ORDER BY id ASC");

in front of the while and now the first result is showing up!

I'm not sure if you understood what I was trying to say with the decimal points, but the meaning of truncate is the opposite of what I'm trying to do. Truncate made the correct amount of decimals but they weren't correct.

I had it work for some numbers such as 31.9, but its also changing into 5.42 into 5.41. Whats it doing??? It should still say 5.42.

#23 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 January 2006 - 06:43 PM

It's not that you're asking too many questions -- ask as many as you want, that's what this forum is all about! It's just that when it's all in one thread, it's often hard to follow when the "question" changes.

TRUNCATE() does exactly that, with no rounding. If you're getting 5.42 becoming 5.41, then that means the "underlying value" is probably 5.419, and whatever is giving you 5.42 is simply rounding. When you truncate, you just chop the number of N decimal places, so you'll get 5.41. Does that make sense?


Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users