1

Here is the php code:

<?php
require_once('../phpFunctions/funciones.php');
conectar('localhost', 'root', '*******', 'tutoriales');

echo "<table cellspacing=\"0\" border=\"1\" cellpadding=\"0\">";
for ($x = 0; $x <= 9; $x++) {
    echo "<tr>";
    for ($y = 0; $y <= 9; $y++) {
        $numero = $x."".$y;   
        $region = (int)$numero;
        $sentencia = @mysql_query('select type,region from tutorial1_estrellas where region='.$region.'');
        $lanzar = @mysql_fetch_object($sentencia);
        if($lanzar[1]==$region){
            switch ($lanzar[0]) {
            case "red":
            echo "<td><img src=\"../images/redRegion.png\"></td>";   
            break;
            case "yellow":
            echo "<td><img src=\"../images/yellowRegion.png\"></td>";   
            break;
            case "blue":
            echo "<td><img src=\"../images/blueRegion.png\"></td>";   
            break;
        }
    } else  
        echo "<td><img src=\"../images/voidRegion.png\"></td>";   
    }   
    echo "</tr>";
}
echo "</table>";
?>

The HTML output looks like a huge ECHO but not a normal table, is this an error or this is normal output in php? I'm new to PHP so please bear with me.

OUTPUT:

"; for ($x = 0; $x "; for ($y = 0; $y if($lanzar[1]==$region){ switch ($lanzar[0]) { case "red": echo ""; break; case "yellow": echo ""; break; case "blue": echo ""; break; } }else echo ""; } echo ""; } echo ""; ?>

The loop makes a 10x10 table where the images of each cell are defined by the result of the SQL query in the switch.

6
  • 1
    what is conectar() ?? Is this a php file ? or a html file ? Commented Oct 15, 2012 at 10:54
  • Enter code in proper format . Commented Oct 15, 2012 at 10:55
  • 2
    @swapnesh Probably connection to db. Commented Oct 15, 2012 at 10:59
  • conectar() is a function created by the OP to connect to the required localhost/root or is what I believe. Es así @user1746758? Commented Oct 15, 2012 at 11:00
  • @PLB yeah very first impression but i just want to make sure if he is refering to this conectar() or mysql_connect() ? Commented Oct 15, 2012 at 11:01

1 Answer 1

1

Please make sure your server is properly set to run PHP instead of displaying it. From the output it looks like your problem is that your web server doesn't run PHP code so your browser tries to display your PHP code as HTML.

Create a PHP file (i.e.: test.php) and put the following into it:

<?php phpinfo(); ?>

Then try to get this file. If the output is not a table with PHP settings, then something is wrong with your web server setup.

Sign up to request clarification or add additional context in comments.

1 Comment

This looks like the problem. I stripped all the code except the table tags and it produced the 10 X 10 matrix. The stripped out code looks valid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.