Jump to content

$dot%12


raman

Recommended Posts

Can someone explain the meaning of $dot%12 in this code :

 

 

$dot = (empty($_GET['dot'])) ? '' : $_GET['dot'];

for($i = 0; $i <= ($dot%12); $i++) {

}

 

This code is in a script called result.php and the script question.php has result.php as its action . But the form in question.php doen't have the variable called dot anywhere .It posts many other varaibles by the method post. Can someone explain then why does dot come in the script result.php ?

Link to comment
Share on other sites

If the URL is 'http://yoursite.com/result.php?dot=3' then $dot will have the value 3 (by getting it from $_GET['dot']). This way you could make a link to result.php and pass a number as the $dot value to it.

 

The % is the modulus operator, as IchBin said. It returns the remainder of dividing the number on the left by the number on the right. It is useful for taking a number that could be a very large number and reduce it to a smaller range of values. For example:

 

0 % 12 == 0

1 % 12 == 1

2 % 12 == 2

...

10 % 12 == 10

11 % 12 == 11

12 % 12 == 0

13 % 12 == 1

14 % 12 == 2

...

22 % 12 == 10

23 % 12 == 11

24 % 12 == 0

 

As you can see, if the number on the left is less than the number on the right, the result is always the number on the left.

 

So what that 'for' loop is doing is looping from the number zero to a number less than twelve, depending on what $dot is. It could be there to make sure that $dot is less than 12, but that wouldn't be a very good way of checking for that.

Link to comment
Share on other sites

Alright I understand modulus.

 

But actually in result.php I see two variables not declared in the form on question.php $opt and $dot.Then in result.php I can see that value is given to $opt( wait)  but not to $opt ,then why is this $dot needed.This is the code :

 



$opt = (empty($_GET['opt'])) ? '' : $_GET['opt'];$dot = (empty($_GET['dot'])) ? '' : $_GET['dot'];
if(!$opt || $opt == 'wait') {
$progressdot = "image/progressdot.png";
echo "<p><strong>Your job is being processed ";
for($i = 0; $i <= ($dot%12); $i++) {
echo "<img src='$progressdot'>";
}
echo "</strong></p>";
$dot += 1;

echo "<p>Please wait here to watch the progress of your job.</p>";
echo "<p>This page will update itself automatically until search is done.</p>";
echo "<p><a href=viroblast.php>Back to ViroBLAST</a></p>";
}

if(!$opt || $opt == 'wait') {
echo "<META HTTP-EQUIV=\"refresh\"
content=\"10;URL=blastresult.php?jobid=$jobid&alignmentView=$alignmentView&opt=wait&dot=$dot\">";
echo "<META HTTP-EQUIV=\"expires\"
  CONTENT=\"now\">";
}

while(!file_exists($filename)) {}

if(!$opt || $opt == 'wait') {
echo "<script LANGUAGE=JavaScript>";
echo "location.replace('blastresult.php?jobid=$jobid&opt=none')";
echo "</script>";
}else {
@ $fp = fopen("$dataPath/$jobid.blastcount.txt", "r");
if(!$fp) {
echo "<p><strong> error: $php_errormsg  </strong></p></body></html>";
exit;
}

Link to comment
Share on other sites

Ok, the $dot is the number of dots that the script will display. The $opt tells the script if it's still in progress or whatever. The <META> tags will cause the page to refresh and will pass $opt and $dot in the URL:

 

echo "<META HTTP-EQUIV=\"refresh\"
content=\"10;URL=blastresult.php?jobid=$jobid&alignmentView=$alignmentView&opt=wait&dot=$dot\">";

 

It looks like for each page refresh, the value of $dot will be incremented by 1, which causes the nice effect of a row of twelve dots animating like this:

 

$dot = 0:
$dot = 1:  .
$dot = 2:  ..
$dot = 3:  ...
$dot = 4:  ....
$dot = 5:  .....
$dot = 6:  ......
$dot = 7:  .......
$dot = 8:  ........
$dot = 9:  .........
$dot = 10: ..........
$dot = 11: ...........
$dot = 12: 
$dot = 13: .
$dot = 14: ..

 

So as $dot keeps incrementing, each page refresh will show one more dot, until it gets to 12, when the number of dots goes back to zero.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.