raman Posted November 8, 2008 Share Posted November 8, 2008 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 ? Quote Link to comment Share on other sites More sharing options...
IchBin Posted November 8, 2008 Share Posted November 8, 2008 The % sign is modulus. Its like saying if $i is less than or equal to the remainder of $dot divided by 12, then add one to $i. Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
raman Posted November 8, 2008 Author Share Posted November 8, 2008 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; } Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
raman Posted November 8, 2008 Author Share Posted November 8, 2008 Yes but in the output which I see on the browser I get the dot displayed only once and when that page refreshes to a new one then two dots appear there.what is the use of $dot in this ? Quote Link to comment Share on other sites More sharing options...
blueman378 Posted November 8, 2008 Share Posted November 8, 2008 as he said $dot is the amount of dots to display... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.