Ik heb een website waar men kan schaken. Daarin zit een script met de volgende funtctie:
function writeHistoryPGN($format = "color", $single = 'none')
{
global $history, $numMoves, $MSG_LANG; $_SESSION;
if ($format == "color"){
echo '<table border="0" width="250" class="TABLE" align="center">';
echo "<tr><th class='THTOP'>Geschiedenis</th></tr>";
echo "<tr><td><div style='width:250;overflow:auto;height:147'><table border='1' width='230' align='center' cellspacing='0' cellpadding='3'>";
echo ("<tr><td bgcolor='#c0c0c0' width='30'><font color=black><b>Zet</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>Wit</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>Zwart</b></font></td></tr>\n");
}
for ($i = 0; $i <= $numMoves; $i+=2)
//for($i = $numMoves; $i >= 0; $i-=2)
{
if ($format == "color")
$export = false;
else $export = true;
if ($format == "color")
echo "<tr><td align='center' bgcolor='#BBBBBB'><font color='black'></font></td><td bgcolor='white' align='center'><font color='black'>";
$tmpReplaced = "";
if (!is_null($history[$i]['replaced']))
$tmpReplaced = $history[$i]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i]['promotedTo']))
$tmpPromotedTo = $history[$i]['promotedTo'];
$tmpCheck = ($history[$i]['isInCheck'] == 1);
if ($format == "plain" && $single != 'single')
{
if (ceil(($i+1)/2) > 1 && $single == 'chess')
{
echo "<br />";
}
echo ceil(($i+1)/2).". ";
}
$last_move=moveToPGNString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck);
$p = mysql_query("UPDATE games SET last_move='".$last_move."' WHERE gameID=".$_SESSION['gameID']."");
* echo moveToPGNString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck, $export, $single)." ";
//$allezettenineentabel[$history[$i+1]]="echo 'curpiece','fromrow','fromcol','torow','tocol', $tmpReplaced, $tmpPromotedTo, $tmpCheck, $export, $single" ;
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='./images/pieces/".$_SESSION['pref_theme']."/black_".$tmpReplaced.".gif' height='15' align='left'> ";
echo ("</font></td><td bgcolor=white align='center'><font color='black'>");
}
if ($i == $numMoves){
if ($format == "color")
echo (" ");
}
else
{
$tmpReplaced = "";
if (!is_null($history[$i+1]['replaced']))
$tmpReplaced = $history[$i+1]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i+1]['promotedTo']))
$tmpPromotedTo = $history[$i+1]['promotedTo'];
$tmpCheck = ($history[$i+1]['isInCheck'] == 1);
if ($format == "plain")
echo ceil(($i+1)/2).". ";
* echo moveToPGNString($history[$i+1]['curColor'], $history[$i+1]['curPiece'], $history[$i+1]['fromRow'], $history[$i+1]['fromCol'], $history[$i+1]['toRow'], $history[$i+1]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck,$export,$single)." ";
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='./images/pieces/".$_SESSION['pref_theme']."/white_".$tmpReplaced.".gif' height='15' align='left'> ";
}
}
if ($format == "color")
echo ("</font></td></tr>\n");
else{
if (floor(($i+1)/8) == ($i)/8 && $i != 0)
echo "\n";
}
}
if ($format == "color")
echo ("</table></div></table>\n");
}
Daarin worden de zetten getoond in de volgorde
1
2
3
Wat ik wil is dat de laatste zet bovenaan staat, dus:
3
2
1
Ik heb geprobeerd met de for loop om te draaien, zoals je kunt zien maar dat lukt niet.
Ik heb de raad gekregen van iemand die wel weet waar hij mee bezig is om alle echo's in een array te zetten nl: ipv echo "echotxt" wordt het $allezettenineentabel[rijnummer]="echotxt";
en op het eind echo implode(array_reverse($allezettenineentabel)); deze in te voegen.
Ik probeer het al een paar weken maar telkens krijg ik een foutmelding.
Is er iemand die mij op weg kan helpen? Ik ben pas begonnen met php en al vele paginas gelezen ivm array'a maar geraak er niet aan uit
gr
Mario