PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hiewall
Forum Newbie
Posts: 11 Joined: Mon Mar 08, 2004 11:02 pm
Post
by hiewall » Fri Jan 14, 2005 9:46 am
I am working with code to shuffle numbers. I am able to use it for my horizontal (top row) and it works fine.
My problem is getting it to work for the vertical ( red) side row.
The problem is that when I apply this same code to the vertical ---- the numbers inside the square get all messed up -- they have to remain 0 thru 99.
Thanks for your help !!!!
The section of code that applies to this problem is :
Code: Select all
<table border=1 width=800 cellspacing=0 cellpadding=5>
<tr>
<td align=center width="9%" height=25 valign=top><font color=black><b></b></font><br><font color=red><b></b></font></td>
<td width="1%"></td>
<?
// THIS IS WHERE ALL OF THE MAGIC HAPPENS. FIRST WE PRINT OUT THE TOP ROW OF SQUARES...
$randarray=array();
for($k=0; $k<=9; $k++) {
$randarrayї] = $k;
}
shuffle($randarray);
foreach ($randarray as $k) {
echo "\t<td width="9%" height=25 align=center><b>"; if ($mystery) { echo "<name=col$k>?"; } else { echo "$k"; } echo "</b></td>\n";
} ?>
<tr>
<td height=10></td>
</tr>
<?
// NOW THE GRID IS BEING PRINTED
for($i=0; $i<=9; $i++) {
$rownew = "row"."$i";
echo "<tr>\n\t<td align=center><font color=red><b>"; if ($mystery) { echo "<name=$rownew>?"; } else { echo "$i"; } echo "</b></font></td><td width="1%"></td>";
for($j=0; $j<=9; $j++) {
$colnew = "col"."$j";
$both_loop = $rownew.$colnew;
$formatted_selection = $rownew.':'.$colnew;
$number = $i.$j;
$digits = sprintf('%2d', $number);
if (${$rownew.$colnew}) {
$pick = "$rownew:$colnew";
echo "\n\t<td width="9%" align=center>"; if ($mystery) { echo "<font color=red><b><name=$rownew>?</b></font> : <b><name=$colnew>?</b>"; } else { echo "<b>$digits</b>"; } echo "<br><font size=1><b>$name</b></font></td>";
} // endwhile
else {
echo "\n\t<td width="9%" align=center>"; if ($mystery) { echo "<font color=red><b><name=$rownew>?</b></font> : <b><name=$colnew>?</b>"; } else { echo "<b>$digits</b>"; } echo "<br><input type=radio name="selection" value="$rownew:$colnew""; if ($selection == $formatted_selection) echo " checked"; echo "></td>";
}
} //for($j=0; $j<=9; $j++) {
echo "\n</tr>\n";
} //for($i=0; $i<=9; $i++) {
?>
</table>
<br>
<? if ($squares_add) { ?>
<input class=button type="submit" value="Submit" name="submit">
<input class=button type="reset" value = "Clear">
<? } ?>
<br><br><a href="http://<?=$website?>">Return to <?=$website?></a>
</center>
</body>
</html>
My entire code is in
http://poolsforfun.com/squares2.php
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Jan 14, 2005 9:58 am
It's difficult to read your code, please wrap it in [syntax=php][/syntax] or [syntax=php][/syntax] (preferably) tags.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
hiewall
Forum Newbie
Posts: 11 Joined: Mon Mar 08, 2004 11:02 pm
Post
by hiewall » Fri Jan 14, 2005 10:09 am
I'm new at this and am not sure what you mean by "wrap your code".
I thought that the code is pretty obvious.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 14, 2005 10:15 am
after it's been placed in formatting, like it is now.. (which I did for you) it becomes easier to read. Posting the code without some form of formatting makes it difficult for us to help..
As for your problem.. where do the variable variables come from? "${$rownew.$colnew}"
Can you post an example of what gets output?
hiewall
Forum Newbie
Posts: 11 Joined: Mon Mar 08, 2004 11:02 pm
Post
by hiewall » Fri Jan 14, 2005 10:22 am
If you just click on the url at the bottom of my original post --- you will see what the code produces.
Thanks for your help
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 14, 2005 10:29 am
that still doesn't answer my first question of where the variable variables come from...
html note: the first table row isn't terminated & should use a span in the second (spacer) row..
hiewall
Forum Newbie
Posts: 11 Joined: Mon Mar 08, 2004 11:02 pm
Post
by hiewall » Fri Jan 14, 2005 10:37 am
Please forgive my ignorance --- but what do you mean --- where do they come from???? They are ceated in the code.
Like I said --- I am kind of new at this --- so please be patient with my ignorance.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 14, 2005 10:53 am
${$rownew.$colnew} isn't "$rownew:$colnew"
this seems to be what you are after more, you'll have to add the magic stuff.. but the randomization is there.
Code: Select all
<?php
$cols = $rows = array();
for($i = 0; $i < 10; $i++)
$rowsї] = $colsї] = $i;
shuffle($rows);
shuffle($cols);
echo '<table width="800" border="1" cellpadding="0" cellspacing="0"><tr><td width="9%"> </td><td width="1%"> </td>';
for($i = 0; $i < 10; $i++)
{
echo '<td width="10%" style="color:black;text-align:center">' . $colsї$i] . '</td>';
}
echo '</tr>'."\n".'<tr><td colspan="12" height="10"> </td></tr>'."\n";
for($i = 0; $i < 10; $i++)
{
echo '<tr><td width="9%" style="color:red;text-align:center">' . $rowsї$i] . '</td><td width="1%"> </td>';
for($j = 0; $j < 10; $j++)
{
echo '<td style="text-align:center" width="10%">' . ($i!=0?$i:'') . $j . '<br /><input type="radio" name="selection" value="row' . $i . ':col' . $j . '" /></td>';
}
echo '</tr>' . "\n";
}
echo '</table>';
?>
hiewall
Forum Newbie
Posts: 11 Joined: Mon Mar 08, 2004 11:02 pm
Post
by hiewall » Sat Jan 15, 2005 9:58 am
Thanks Feyd ----- this is exactly what I needed. I really appreciate your help.