469,921 Members | 2,183 Online

# Help understanding a script

I was wondering if anyone can help explain this code for me

[CODE
]<table width="<?= \$TABLE_WIDTH ?>" border="0" cellspacing="0" cellpadding="0">
<?php
for (\$x=1; \$x<=pow(2, \$COLUMNS); \$x++) {
// open the row
printf('<tr>');

// draw each of the columns in this row...
for (\$y=1; \$y<=\$COLUMNS; \$y++) {

// begin with a default style
\$style = "line";
\$value = "";

// Determine the content for the data cells (if there is any) and
// add the underline style always
if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
[/code]
From what I try to understand this code

Expand|Select|Wrap|Line Numbers
1. if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
2.
would be a smaller number divided by a larger number and would give the remainder. I have tried a smaller number divided by a larger number in a simple script, but the remainder always seems to equal the smaller number.

[code]
<?php
\$a=6;
\$b=11;
\$c=\$a%\$b;

echo "\$a % \$b = \$c";

?>
Mar 20 '06 #1
7 1281
Message-ID: <q9mTf.1326\$3t1.818@trndny08> from <ne****@php.world>
contained the following:
would be a smaller number divided by a larger number and would give the remainder. I have tried a smaller number divided by a larger number in a simple script, but the remainder always seems to equal the smaller number.

well...yeah.

six divided by eleven = zero, remainder six

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 20 '06 #2
Interesting. Back when I was taught this in school you would skip the units
and put a decimal and move to the tenths and change six to sixty, thereby
never knowing this. Any whoo still dont understand script.
Mar 20 '06 #3
Message-ID: <5FmTf.1327\$3t1.1243@trndny08> from ME@newbie.com contained
the following:
Interesting. Back when I was taught this in school you would skip the units
and put a decimal and move to the tenths and change six to sixty, thereby
never knowing this. Any whoo still dont understand script.

What is it supposed to do?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Mar 20 '06 #4
Geoff Berrow wrote:
Message-ID: <5FmTf.1327\$3t1.1243@trndny08> from ME@newbie.com contained
the following:
Interesting. Back when I was taught this in school you would skip the units
and put a decimal and move to the tenths and change six to sixty, thereby
never knowing this. Any whoo still dont understand script.

What is it supposed to do?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

I can't figure out what it's supposed to do. Do you have more code?
There is definitely a regular relationship as the code below shows.
But what is that relationship used for?
<?php
echo '<tr><th>\$x</th><th>\$y</th><th>\$x % pow(2, \$y)</th><th>pow(2,
\$y-1)</th>';
echo
'<th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th>';
echo '<th>8</th><th>9</th><th>10</th></tr>';
for (\$x=1; \$x<=pow(2, 10); \$x++) {
for (\$y=1; \$y<=10; \$y++) {

\$xcmp = \$x % pow(2, \$y);
\$ycmp = pow(2, \$y-1);
if (\$xcmp == \$ycmp) {
echo "<tr><td>\$x</td><td>\$y</td><td
align=\"center\">".\$xcmp."</td>";
echo "<td align=\"center\">".\$ycmp."</td>";
for (\$i=1; \$i<=10; \$i++){
if (\$i == \$ycmp) echo "<td>X</td>";
else echo "<td>&nbsp</td>";
}
echo "</tr>";
}
}
}
echo '</table>';
?>

Mar 20 '06 #5
On Sun, 19 Mar 2006 23:52:54 +0000, newbie wrote:
I was wondering if anyone can help explain this code for me

Expand|Select|Wrap|Line Numbers
1.   <table width="<?= \$TABLE_WIDTH ?>" border="0" cellspacing="0"
3.  <?php
4.  for (\$x=1; \$x<=pow(2, \$COLUMNS); \$x++) {
5.      // open the row
6.      printf('<tr>');
7.      // draw each of the columns in this row...
8.      for (\$y=1; \$y<=\$COLUMNS; \$y++) {
9.          // begin with a default style
10.          \$style = "line";
11.          \$value = "";
12.          // Determine the content for the data cells (if there is any)
13.          // and add the underline style always
14.          if ((\$x % pow(2, \$y)) ==  pow(2, \$y-1)) {
15.

From what I try to understand this code

Expand|Select|Wrap|Line Numbers
1.   if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
2.

would be a smaller number divided by a larger number and would give the
remainder. I have tried a smaller number divided by a larger number in a
simple script, but the remainder always seems to equal the smaller
number.

Not always. \$x is often bigger than pow(2, \$y). It looks like code you'd
use to layout the draw in an N-round knockout tournament (N == \$COLUMNS):

The cells selected by that test alternate in the first column, are one in
four of the second, one in eight in the third and so on... All lined up
so no row has more than one selected cell. It is quite clever but it
could do with a comment or two, though!

What is it actually for?

--
Ben.
Mar 20 '06 #6
Yes it is for a round knockout tournament, it uses a ini file for data. I
want to convert the script to be used in a database for a site. Here is the
rest of the code. I found it on the internet, the guys was giving the code
is actually the ini file that was name .txt that i switch to .php thinking i
could use it for variable and getting info from the db, which i have found I
can't, and need to recode everything but the math.

Expand|Select|Wrap|Line Numbers
1. ________________________________________________________________________________________________________________
2.
3. [bracket]
4. columns = 5;
5. column_width = 120;
6. title = "Your Title Here";
7.
8. [column7]
9. 1 = ""
10. 2 = ""
11. 3 = ""
12. 4 = ""
13. 5 = ""
14. 6 = ""
15. 7 = ""
16. 8 = ""
17. 9 = ""
18. 10 = ""
19. 11 = ""
20. 12 = ""
21. 13 = ""
22. 14 = ""
23. 15 = ""
24. 16 = ""
25. 17 = ""
26. 18 = ""
27. 19 = ""
28. 20 = ""
29. 21 = ""
30. 22 = ""
31. 23 = ""
32. 24 = ""
33. 25 = ""
34. 26 = ""
35. 27 = ""
36. 28 = ""
37. 29 = ""
38. 30 = ""
39. 31 = ""
40. 32 = ""
41. 33 = ""
42. 34 = ""
43. 35 = ""
44. 36 = ""
45. 37 = ""
46. 38 = ""
47. 39 = ""
48. 40 = ""
49. 41 = ""
50. 42 = ""
51. 43 = ""
52. 44 = ""
53. 45 = ""
54. 46 = ""
55. 47 = ""
56. 48 = ""
57. 49 = ""
58. 50 = ""
59. 51 = ""
60. 52 = ""
61. 53 = ""
62. 54 = ""
63. 55 = ""
64. 56 = ""
65. 57 = ""
66. 58 = ""
67. 59 = ""
68. 60 = ""
69. 61 = ""
70. 62 = ""
71. 63 = ""
72. 64 = ""
73.
74. [column6]
75. 1 = ""
76. 2 = ""
77. 3 = ""
78. 4 = ""
79. 5 = ""
80. 6 = ""
81. 7 = ""
82. 8 = ""
83. 9 = ""
84. 10 = ""
85. 11 = ""
86. 12 = ""
87. 13 = ""
88. 14 = ""
89. 15 = ""
90. 16 = ""
91. 17 = ""
92. 18 = ""
93. 19 = ""
94. 20 = ""
95. 21 = ""
96. 22 = ""
97. 23 = ""
98. 24 = ""
99. 25 = ""
100. 26 = ""
101. 27 = ""
102. 28 = ""
103. 29 = ""
104. 30 = ""
105. 31 = ""
106. 32 = ""
107.
108. [column5]
109. 1 = "team name between quotes"
110. 2 = ""
111. 3 = ""
112. 4 = ""
113. 5 = ""
114. 6 = ""
115. 7 = ""
116. 8 = ""
117. 9 = ""
118. 10 = ""
119. 11 = ""
120. 12 = ""
121. 13 = ""
122. 14 = ""
123. 15 = ""
124. 16 = ""
125.
126. [column4]
127. 1 = ""
128. 2 = ""
129. 3 = ""
130. 4 = ""
131. 5 = ""
132. 6 = ""
133. 7 = ""
134. 8 = ""
135.
136. [column3]
137. 1 = ""
138. 2 = ""
139. 3 = ""
140. 4 = ""
141.
142. [column2]
143. 1 = ""
144. 2 = ""
145.
146. [column1]
147. 1 = "<i>Champion</i>"
148.
149.
150.
151. ________________________________________________________________________________________________________________
152.
153.
154. <?php
155. //----------------------------------------------------------------------
156. \$DATA         = parse_ini_file("data_sheet.php", true);
157. \$COLUMNS      = \$DATA["bracket"]["columns"];
158. \$COLUMN_WIDTH = \$DATA["bracket"]["column_width"];
159. \$TABLE_WIDTH  = \$COLUMN_WIDTH * \$COLUMNS;
160. //----------------------------------------------------------------------
161. ?>
162. <html>
164. <title><?= htmlspecialchars(\$DATA["bracket"]["title"]); ?></title>
165. <style type="text/css">
166. P {
167. font-family : Arial, Helvetica, sans-serif;
168. font-size : 11px;
169. font-weight : normal;
170. color : Black;
171. }
172. EM {
173. font-family : Arial, Helvetica, sans-serif;
174. font-size : 11px;
175. font-weight : normal;
176. color : #CC0000;
177. }
178. A {
179. font-family : Arial, Helvetica, sans-serif;
180. font-size : 11px;
181. font-weight : normal;
182. color : Blue;
183. }
184. .line {
185. font-family : Arial, Helvetica, sans-serif;
186. font-size : 11px;
187. font-weight : normal;
188. padding : 1px 3px 1px 3px;
189.
190. }
191. .line-right {
192. font-family : Arial, Helvetica, sans-serif;
193. font-size : 11px;
194. font-weight : normal;
195. padding : 1px 3px 1px 3px;
196. border-right : 1px solid Red;
197. }
198. .line-under {
199. font-family : Arial, Helvetica, sans-serif;
200. font-size : 11px;
201. font-weight : normal;
202. padding : 1px 3px 1px 3px;
203. border-bottom : 1px solid Green;
204. }
205. .line-under-right {
206. font-family : Arial, Helvetica, sans-serif;
207. font-size : 11px;
208. font-weight : normal;
209. padding : 1px 3px 1px 3px;
210. border-bottom : 1px solid Blue;
211. border-right : 1px solid Grey;
212. }
213. .right {
214. font-family : Arial, Helvetica, sans-serif;
215. font-size : 11px;
216. font-weight : bold;
217. color : Green;
218. }
219. .wrong {
220. font-family : Arial, Helvetica, sans-serif;
221. font-size : 11px;
222. font-weight : bold;
223. color : Red;
224. }
225. </style>
227.
228. <body bgcolor="blue" leftmargin="20" topmargin="20" rightmargin="20"
229. bottommargin="20" marginwidth="20">
230. <div align="center">
231. <table width="700" border="0" cellspacing="0" cellpadding="20"
232. bgcolor="gray">
233. <tr>
234. <td align="center" valign="top">
235. <p>
236.
237. <h1 style="font-family: Arial, Helvetica, sans-serif;">
238. <?= htmlspecialchars(\$DATA["bracket"]["title"]); ?>
239. </h1>
240.
241. <table width="<?= \$TABLE_WIDTH ?>" border="0" cellspacing="0"
243. <?php
244. for (\$x=1; \$x<=pow(2, \$COLUMNS); \$x++) {
245. // open the row
246. printf('<tr>');
247.
248. // draw each of the columns in this row...
249. for (\$y=1; \$y<=\$COLUMNS; \$y++) {
250.
251. // begin with a default style
252. \$style = "line";
253. \$value = "";
254.
255. // Determine the content for the data cells (if there is any) and
256. // add the underline style always
257. if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
258. \$round    = "column" . (\$COLUMNS - \$y +1);
259. \$posit    = ceil(\$x/pow(2, \$y));
260. \$data    = (isset(\$DATA[\$round][\$posit])) ?
261. trim(\$DATA[\$round][\$posit]) : '';
262. \$parts    = split("\|", \$data);
263. \$value    = array_shift(\$parts);
264. \$value    = sprintf(\$value);
265. \$style .= "-under";
266. }
267.
268. // Add the right bar line for cells that need it...
269. if (\$y != \$COLUMNS) {
270. if (((\$x + pow(2, \$y-1) - 1) % pow(2, \$y+1)) >= pow(2, \$y)) {
271. \$style .= "-right";
272. }
273. }
274.
275. // make sure we don't print empty content
276. if (empty(\$value)) {
277. \$value = "&nbsp;";
278. }
279.
280. // draw this cell
281. printf('<td width="%d" class="%s">%s</td>',
282. \$COLUMN_WIDTH, \$style, \$value);
283. print("\n");
284. }
285.
286. // close the row
287. printf("</tr>\n");
288. }
289. ?>
290. </table>
291. </p>
292.
293. <p align="left">
294. ****NOTE****<br>
295. </p>
296. </td>
297. </tr>
298. </table>
299.
300. </div>
301.
302.
303. </body>
304. </html>
305.
Any help with converting code to be used with a db would be greatly
appreciated.
Mar 20 '06 #7
Yes it is for a round knockout tournament, it uses a ini file for data. I
want to convert the script to be used in a database for a site. Here is the
rest of the code. I found it on the internet, the guys was giving the code
is actually the ini file that was name .txt that i switch to .php thinking i
could use it for variable and getting info from the db, which i have found I
can't, and need to recode everything but the math.

Expand|Select|Wrap|Line Numbers
1. ________________________________________________________________________________________________________________
2.
3. [bracket]
4. columns = 5;
5. column_width = 120;
6. title = "Your Title Here";
7.
8. [column7]
9. 1 = ""
10. 2 = ""
11. 3 = ""
12. 4 = ""
13. 5 = ""
14. 6 = ""
15. 7 = ""
16. 8 = ""
17. 9 = ""
18. 10 = ""
19. 11 = ""
20. 12 = ""
21. 13 = ""
22. 14 = ""
23. 15 = ""
24. 16 = ""
25. 17 = ""
26. 18 = ""
27. 19 = ""
28. 20 = ""
29. 21 = ""
30. 22 = ""
31. 23 = ""
32. 24 = ""
33. 25 = ""
34. 26 = ""
35. 27 = ""
36. 28 = ""
37. 29 = ""
38. 30 = ""
39. 31 = ""
40. 32 = ""
41. 33 = ""
42. 34 = ""
43. 35 = ""
44. 36 = ""
45. 37 = ""
46. 38 = ""
47. 39 = ""
48. 40 = ""
49. 41 = ""
50. 42 = ""
51. 43 = ""
52. 44 = ""
53. 45 = ""
54. 46 = ""
55. 47 = ""
56. 48 = ""
57. 49 = ""
58. 50 = ""
59. 51 = ""
60. 52 = ""
61. 53 = ""
62. 54 = ""
63. 55 = ""
64. 56 = ""
65. 57 = ""
66. 58 = ""
67. 59 = ""
68. 60 = ""
69. 61 = ""
70. 62 = ""
71. 63 = ""
72. 64 = ""
73.
74. [column6]
75. 1 = ""
76. 2 = ""
77. 3 = ""
78. 4 = ""
79. 5 = ""
80. 6 = ""
81. 7 = ""
82. 8 = ""
83. 9 = ""
84. 10 = ""
85. 11 = ""
86. 12 = ""
87. 13 = ""
88. 14 = ""
89. 15 = ""
90. 16 = ""
91. 17 = ""
92. 18 = ""
93. 19 = ""
94. 20 = ""
95. 21 = ""
96. 22 = ""
97. 23 = ""
98. 24 = ""
99. 25 = ""
100. 26 = ""
101. 27 = ""
102. 28 = ""
103. 29 = ""
104. 30 = ""
105. 31 = ""
106. 32 = ""
107.
108. [column5]
109. 1 = "team name between quotes"
110. 2 = ""
111. 3 = ""
112. 4 = ""
113. 5 = ""
114. 6 = ""
115. 7 = ""
116. 8 = ""
117. 9 = ""
118. 10 = ""
119. 11 = ""
120. 12 = ""
121. 13 = ""
122. 14 = ""
123. 15 = ""
124. 16 = ""
125.
126. [column4]
127. 1 = ""
128. 2 = ""
129. 3 = ""
130. 4 = ""
131. 5 = ""
132. 6 = ""
133. 7 = ""
134. 8 = ""
135.
136. [column3]
137. 1 = ""
138. 2 = ""
139. 3 = ""
140. 4 = ""
141.
142. [column2]
143. 1 = ""
144. 2 = ""
145.
146. [column1]
147. 1 = "<i>Champion</i>"
148.
149.
150.
151. ________________________________________________________________________________________________________________
152.
153.
154. <?php
155. //----------------------------------------------------------------------
156. \$DATA         = parse_ini_file("data_sheet.php", true);
157. \$COLUMNS      = \$DATA["bracket"]["columns"];
158. \$COLUMN_WIDTH = \$DATA["bracket"]["column_width"];
159. \$TABLE_WIDTH  = \$COLUMN_WIDTH * \$COLUMNS;
160. //----------------------------------------------------------------------
161. ?>
162. <html>
164. <title><?= htmlspecialchars(\$DATA["bracket"]["title"]); ?></title>
165. <style type="text/css">
166. P {
167. font-family : Arial, Helvetica, sans-serif;
168. font-size : 11px;
169. font-weight : normal;
170. color : Black;
171. }
172. EM {
173. font-family : Arial, Helvetica, sans-serif;
174. font-size : 11px;
175. font-weight : normal;
176. color : #CC0000;
177. }
178. A {
179. font-family : Arial, Helvetica, sans-serif;
180. font-size : 11px;
181. font-weight : normal;
182. color : Blue;
183. }
184. .line {
185. font-family : Arial, Helvetica, sans-serif;
186. font-size : 11px;
187. font-weight : normal;
188. padding : 1px 3px 1px 3px;
189.
190. }
191. .line-right {
192. font-family : Arial, Helvetica, sans-serif;
193. font-size : 11px;
194. font-weight : normal;
195. padding : 1px 3px 1px 3px;
196. border-right : 1px solid Red;
197. }
198. .line-under {
199. font-family : Arial, Helvetica, sans-serif;
200. font-size : 11px;
201. font-weight : normal;
202. padding : 1px 3px 1px 3px;
203. border-bottom : 1px solid Green;
204. }
205. .line-under-right {
206. font-family : Arial, Helvetica, sans-serif;
207. font-size : 11px;
208. font-weight : normal;
209. padding : 1px 3px 1px 3px;
210. border-bottom : 1px solid Blue;
211. border-right : 1px solid Grey;
212. }
213. .right {
214. font-family : Arial, Helvetica, sans-serif;
215. font-size : 11px;
216. font-weight : bold;
217. color : Green;
218. }
219. .wrong {
220. font-family : Arial, Helvetica, sans-serif;
221. font-size : 11px;
222. font-weight : bold;
223. color : Red;
224. }
225. </style>
227.
228. <body bgcolor="blue" leftmargin="20" topmargin="20" rightmargin="20"
229. bottommargin="20" marginwidth="20">
230. <div align="center">
231. <table width="700" border="0" cellspacing="0" cellpadding="20"
232. bgcolor="gray">
233. <tr>
234. <td align="center" valign="top">
235. <p>
236.
237. <h1 style="font-family: Arial, Helvetica, sans-serif;">
238. <?= htmlspecialchars(\$DATA["bracket"]["title"]); ?>
239. </h1>
240.
241. <table width="<?= \$TABLE_WIDTH ?>" border="0" cellspacing="0"
243. <?php
244. for (\$x=1; \$x<=pow(2, \$COLUMNS); \$x++) {
245. // open the row
246. printf('<tr>');
247.
248. // draw each of the columns in this row...
249. for (\$y=1; \$y<=\$COLUMNS; \$y++) {
250.
251. // begin with a default style
252. \$style = "line";
253. \$value = "";
254.
255. // Determine the content for the data cells (if there is any) and
256. // add the underline style always
257. if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
258. \$round    = "column" . (\$COLUMNS - \$y +1);
259. \$posit    = ceil(\$x/pow(2, \$y));
260. \$data    = (isset(\$DATA[\$round][\$posit])) ?
261. trim(\$DATA[\$round][\$posit]) : '';
262. \$parts    = split("\|", \$data);
263. \$value    = array_shift(\$parts);
264. \$value    = sprintf(\$value);
265. \$style .= "-under";
266. }
267.
268. // Add the right bar line for cells that need it...
269. if (\$y != \$COLUMNS) {
270. if (((\$x + pow(2, \$y-1) - 1) % pow(2, \$y+1)) >= pow(2, \$y)) {
271. \$style .= "-right";
272. }
273. }
274.
275. // make sure we don't print empty content
276. if (empty(\$value)) {
277. \$value = "&nbsp;";
278. }
279.
280. // draw this cell
281. printf('<td width="%d" class="%s">%s</td>',
282. \$COLUMN_WIDTH, \$style, \$value);
283. print("\n");
284. }
285.
286. // close the row
287. printf("</tr>\n");
288. }
289. ?>
290. </table>
291. </p>
292.
293. <p align="left">
294. ****NOTE****<br>
295. </p>
296. </td>
297. </tr>
298. </table>
299.
300. </div>
301.
302.
303. </body>
304. </html>
305.
Any help with converting code to be used with a db would be greatly
appreciated.
<ne****@php.world> wrote in message news:q9mTf.1326\$3t1.818@trndny08...
I was wondering if anyone can help explain this code for me

[CODE
]<table width="<?= \$TABLE_WIDTH ?>" border="0" cellspacing="0"
<?php
for (\$x=1; \$x<=pow(2, \$COLUMNS); \$x++) {
// open the row
printf('<tr>');

// draw each of the columns in this row...
for (\$y=1; \$y<=\$COLUMNS; \$y++) {

// begin with a default style
\$style = "line";
\$value = "";

// Determine the content for the data cells (if there is any) and
// add the underline style always
if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
[/code]
From what I try to understand this code

Expand|Select|Wrap|Line Numbers
1.  if ((\$x % pow(2, \$y)) == pow(2, \$y-1)) {
2.

would be a smaller number divided by a larger number and would give the
remainder. I have tried a smaller number divided by a larger number in a
simple script, but the remainder always seems to equal the smaller number.

[code]
<?php
\$a=6;
\$b=11;
\$c=\$a%\$b;

echo "\$a % \$b = \$c";

?>

Mar 21 '06 #8

### This discussion thread is closed

Replies have been disabled for this discussion.