Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 Join the friendly bunch on IRC... (#TalkPHP on Freenode) ...Also available via a web interface. See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
 Associates
 Associates
 TalkPHP » Scratching my head a bit...
 05-22-2010, 08:45 PM #1 (permalink) The Acquainted   Join Date: Nov 2009 Location: nr Stratford-Upon-Avon Posts: 137 Thanks: 3 Scratching my head a bit... I know someone is going to come up with a simple solution to a problem I'm having... I need to divide a given length (x) by a number (a) to give me a value between (y) and (z) e.g x = 3312 y = 181.6 z = 188.39 a = 18 Result = 184 I did that just with basic math and a bit of human brain power "fuzzy logic" and an educated guess... Anyone got any ideas how I might go about doing this in php, the code I imagine will be easy it's just am getting lost in while's, if's and then's .... Please help my sanity !!!!! __________________ Thanks... Simon Sex, Drugs & Linux Rules
 05-22-2010, 09:20 PM #2 (permalink) The Contributor     Join Date: Nov 2007 Location: Nashville, TN Posts: 66 Thanks: 20 Turn your fuzzy brain logic into basic algebra. Then try a google search for doing basic math in php. If your basic code is flawed, post it here and we'll see what we see. __________________ I am not a programmer, nor do I play one on tv.
 05-23-2010, 05:36 AM #3 (permalink) Wizard       Join Date: Sep 2007 Posts: 1,299 Thanks: 17 Using algebra: Those two point are your bounds, anything within them will do the job. If the ceil of the result or the floor of the result is within the bounds use that. Otherwise you will have to go with some sort of a decimal. __________________
 The Following User Says Thank You to Village Idiot For This Useful Post:
 maeltar (05-23-2010)
 05-23-2010, 06:00 AM #4 (permalink) The Acquainted   Join Date: Nov 2009 Location: nr Stratford-Upon-Avon Posts: 137 Thanks: 3 Brilliant, thank you very much I can just loop (a) from 1 ... 30 for each (x) I knew it'd be a relatively simple answer, but sometimes when you stare at a problem you can't see the solution.. Thanks again guys :D __________________ Thanks... Simon Sex, Drugs & Linux Rules
 05-23-2010, 06:09 AM #5 (permalink) Wizard       Join Date: Sep 2007 Posts: 1,299 Thanks: 17 Loop a? I'm not sure what you mean by that. Out of interest, what are you trying to do with this? __________________
 05-23-2010, 06:21 AM #6 (permalink) The Acquainted   Join Date: Nov 2009 Location: nr Stratford-Upon-Avon Posts: 137 Thanks: 3 Ok... it's to work out how many stairs are required for a staircase... x = Height of floor y and z are the min and max rise allowed per stair at a given angle (UK Building Regulations) so (a) has got to be a whole number as thats the quantity of stairs, but this is not known until it's calculated by iterating though a loop to find out what value fits... so the way I see it I need to do something like \$a = 1 while x / \$a > y \$a ++ followed by \$a = 50 while x / \$a < z \$a-- Something on those lines (Obviously have simplified it for easier reading) That should give me the max and min quantity of steps in the staircase... So need to round (a) to the nearest whole number and do a quick.. (x) / (a) to give me the exact rise of step which will be between (y) and (z) __________________ Thanks... Simon Sex, Drugs & Linux Rules
Wizard

Join Date: Sep 2007
Posts: 1,299
Thanks: 17

That seems like a good method.

Quote:
 Originally Posted by maeltar Ok... it's to work out how many stairs are required for a staircase... x = Height of floor y and z are the min and max rise allowed per stair at a given angle (UK Building Regulations) so (a) has got to be a whole number as thats the quantity of stairs, but this is not known until it's calculated by iterating though a loop to find out what value fits... so the way I see it I need to do something like \$a = 1 while x / \$a > y \$a ++ followed by \$a = 50 while x / \$a < z \$a-- Something on those lines (Obviously have simplified it for easier reading) That should give me the max and min quantity of steps in the staircase... So need to round (a) to the nearest whole number and do a quick.. (x) / (a) to give me the exact rise of step which will be between (y) and (z)
__________________

 05-23-2010, 05:57 PM #8 (permalink) The Acquainted   Join Date: Nov 2009 Location: nr Stratford-Upon-Avon Posts: 137 Thanks: 3 here it is.... Seems to work well, may not be "up to standard" but it's a work in progress !!! Probably a bit mixed up as have thrown it together but the functionality is all am bothered about right now, can pretty it up once am happy with everything... Now am playing with GD to overlay text and dimensions on the image http://sparks.homelinux.net/astromezz/med_stringer.png Once I have done that I want to be able to make a link so it can be downloaded as a pdf, have had a quick look at fpdf, and went back to GD... Lots to do for a bit of fun.. PHP Code: ``` Astromezz Stringer Calculator "; echo ""; echo "
Job No. : " . \$j_ref . ""; echo "Name Ref. : " . \$j_name . ""; echo "           STAIRCASE DETAILS     "; echo "

"; echo "

"; echo ""; function calc_steps(\$y,\$z,\$x,\$w) { #  \$y = Min step Height #  \$z = Max Step Height #  \$x = Deck (floor) height #  \$w = Stringer (stair) length # # \$aa = 1;    #### Increment steps 1 ...   while ( (\$x / \$aa) > \$y )     {     \$aa++;     } echo "
Rises in flight :" . (\$aa - 1) . "
Tread Rise Height :" . round((\$x / (\$aa - 1)),2) . "
Going Along Flat : " . round((\$w / (\$aa - 1)),1) . "
Stringer Length : " . round(\$str_len,1) . "
Floor Length : " . round(\$floor_len,1) . "
Stair Angle : " . \$d_angle ?>°";         calc_steps(175,181.59,\$d_height,\$str_len);         break;     case "36";         \$str_len = \$d_height * 1.701;                 \$floor_len = \$d_height * 1.376;                 echo "
Stringer Length : " . round(\$str_len,1) . "
Floor Length : " . round(\$floor_len,1) . "
Stair Angle : " . \$d_angle ?>°";         calc_steps(181.6,188.39,\$d_height,\$str_len);         break;     case "37";         \$str_len = \$d_height * 1.6617;         \$floor_len = \$d_height * 1.327;                 echo "
Stringer Length : " . round(\$str_len,1) . "
Floor Length : " . round(\$floor_len,1) . "
Stair Angle : " . \$d_angle ?>°";         calc_steps(188.4,190,\$d_height,\$str_len);         break; }  ## end case ?> Qty of Stringer Pairs Required :  ``` __________________ Thanks... Simon Sex, Drugs & Linux Rules
"; echo ""; echo ""; if ( (\$x / (\$aa - 1)) > \$z )         {         echo "
Rise Height greater than max allowed !!! (". \$z . "mm)";         echo "
Using one extra step (". \$aa .") would give a Rise height of : ";         echo round(\$x / (\$aa),2) . "mm";     echo "
But that is below the Minimum Rise height of " . \$y . "mm";         } } switch (\$d_angle){     case "35";         \$str_len = \$d_height * 1.743;         \$floor_len = \$d_height * 1.428;         echo "Deck Height : " . \$d_height . "";         echo "";         echo "";         echo "Deck Height : " . \$d_height . "";                 echo "";                 echo "";                 echo "Deck Height : " . \$d_height . "";                 echo "";                 echo "";                 echo "

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On