een array echo'en

Status
Niet open voor verdere reacties.

Mario1966

Nieuwe gebruiker
Lid geworden
15 jan 2015
Berichten
1
Hoi allemaal,

Ik ben nieuw hier en ook redelijk nieuw in PHP, laat ons stellen dat ik quasi een leek ben.
Ik heb een schaaksite en daarin is er een scirpt met de volgende functie
Code:
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)
//for ($i = $numMoves; $i >= 0; $i--) //verbose
        {


                if ($format == "color")
                $export = false;
                else $export = true;

                if ($format == "color")
               * echo ("<tr><td align='center' bgcolor='#BBBBBB'><font color='black'>".(($i/2) + 1)."</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)." ";
                $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 ("&nbsp;");
                }
                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");

}

Deze functie beeld de zetgeschiedenis af als volgt
zet 1
2
3
Nu wil ik de zetten omdraaien, dus=
zet 3
2
1
Ik heb geprobeerd met de for loop te draaien maar dat lukt niet,
er heeft mij iemand de raad gegeven de echos in een arrat te zetten dus:
ipv echo "echotxt" wordt het $allezettenineentabel[rijnummer]="echotxt";
Het gaat meer bepaald over de echo's met een * voor
En dan op het eind van de functie
Code:
echo implode(array_reverse($allezettenineentabel));
toe te voegen.
Daar ik een leek ben is het voor mij moeilijker dan ik dacht.
Dus mijn vraag:
Wie kan er mij helpen?
Dank bij voorbaat
Mario
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan