Jump to content
Sign in to follow this  
xenomorf

Generate Nombor Di Php

Recommended Posts

salam semua.. ada sesiapa yang tahu mcm mana nk auto-generate nombor bermula dari 0.0 sampai 7.0.

sy nk nombor yg di generate tu ada titik perpuluhan. cthnya >> 0.00, 0.50, 1.00, 1.50, .... selang 0.5 setiap nombor.

setakat ni, sy dpt generate nombor bulat (0, 1, 2, 3...) sj. x dpt plak generate nombor yang ada titik perpuluhan.

Share this post


Link to post
Share on other sites
[quote name='xenomorf' date='16 September 2010 - 10:05 PM' timestamp='1284645950' post='1047930']
salam semua.. ada sesiapa yang tahu mcm mana nk auto-generate nombor bermula dari 0.0 sampai 7.0.

sy nk nombor yg di generate tu ada titik perpuluhan. cthnya >> 0.00, 0.50, 1.00, 1.50, .... selang 0.5 setiap nombor.

setakat ni, sy dpt generate nombor bulat (0, 1, 2, 3...) sj. x dpt plak generate nombor yang ada titik perpuluhan.
[/quote]
Salam..

mcm ni kot:

[code]
for ($i=0;$i<=7;$i=$i+0.5)
{
printf("%0.2f",$i);
echo "<br>";
}
[/code]

Share this post


Link to post
Share on other sites
trima kasih utk kod tu. da dpt bt. okay,, cuba tgok kod ni >>
[code]<html>
<head>
</head>
<body bgcolor="#ffffff" text="#808080">
<?php
// will create a table for us
echo '
<table border=1>
<tr>
<th>Penetration</th>
<th>Force (Div) </th>
<th>Force (kN) </th>
</tr>';
// creating the table data a.k.a <td>
for ($y=0;$y<=7;$y=$y+0.5) {
$ys = $y+1; // use for the ID later (Force, Div)
$yai = $y+2; // use for the ID later (Force, kN)
echo '
<tr>
<td>'.printf("%0.2f",$y).'</td>
<td><input type="text" size="25px" id="'.$ys.'" /></td>
<td><input type="text" size="25px" id="'.$yai.'"/></td>
</tr>
';
}
echo '</table>';
?>

</body>
</html>[/code]

tiada masalah kn?
tp bila sy run kod tu, nilai printf x masuk dlm tag <td>...</td>.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...