View Full Version : Some Math Help Needed

Troy McCormick
02-05-2007, 11:58 PM
Alright...so I'm making this poker web site and I need a bit of help displaying the chips when a bet is made. I currently am able to calculate how many of each denomination is needed to fulfill the bet, but I don't know how to go about displaying them.

My denominations are:

$1, $5, $25, $100, $1000, $5000, $25000, $100000

I then pass the bet amount to a function that provides me this information:

[1] => 0
[5] => 1
[25] => 0
[100] => 7
[1000] => 0
[5000] => 0
[25000] => 0
[100000] => 0

This shows how many of each chip is needed to be displayed. On the page for this to be displayed I have two rows of ten stacks. Each stack contains six chips. Stacks are labeled from 0 to 9 and chips are labeled from 0 to 5.

I have tried for loops and such but just can't seem to get it to work correctly. Does anyone have any ideas?

Thanks a ton,


02-06-2007, 03:43 PM
I would take a CSS graphic approach to this:

In my example: http://www.catpin.com/poker/

View the HTML source of my example and see how the height
is altered in each <div> ... overflow is hidden.

This is the PHP script:

<head><title>poker chip display</title>

background: url(chips.gif) no-repeat;

$onechip=42; // the height of one chip
$pile1 = array(4,10,2,5,3);
foreach ($pile1 as $count)
$chips = $onechip*$count;
echo"<div class='col' style='height:".$chips."px;'></div> \n";

I have one graphic image with all 10 chips.
I then only display a certain amount of the image by
cutting-off the image with "height" of the <div>.

This would render very fast and is easy to implement.

You of course create any graphic images of chips that you want.
They could be chips from a side-view, or top-view (like I did).

You could also do it horizontally by creating a horizontal graphic
and adjusting the width instead of height.


02-06-2007, 04:14 PM
That's pretty clever mlseim, a very novel approach even. :)