0
mysql_query($query,$con);

        $query = "SELECT * FROM NW_WORLD;";
        $result = mysql_query($query, $con);

        $i = 0;
        $counter = count($result);
        while($result)
        {
            $village = mysql_result($result, $i, "village");
            $player = mysql_result($result, $i, "player");

            echo "village: $village  ";
            echo "player: $player<br>";
            $i++;
        }

I want to print all the data that I got from the Select statement. This code is working, but after the end of the table I am getting some erroneous data.

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 6788 on MySQL result index 4 in C:\xampp\htdocs\debal\nw_check_exec.php on line 41
village: player:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 6789 on MySQL result index 4 in C:\xampp\htdocs\debal\nw_check_exec.php on line 40
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 6789 on MySQL result index 4 in C:\xampp\htdocs\debal\nw_check_exec.php on line 41
village: player:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 6790 on MySQL result index 4 in C:\xampp\htdocs\debal\nw_check_exec.php on line 40
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 6790 on MySQL result index 4 in C:\xampp\htdocs\debal\nw_check_exec.php on line 41
village: player:

Please could you help me out?

2
  • 1
    Please, don't use mysql_* functions to write new code. They are no longer maintained and the community has begun deprecation process. Instead you should learn about prepared statements and use either PDO or MySQLi. Commented Aug 28, 2012 at 22:00
  • $counter = count($result); by using count on a resource you will only get the value of 1. I don't see the point of that in your code. Commented Aug 28, 2012 at 22:08

2 Answers 2

2

have you tried :

mysql_query($query,$con);

        $query = "SELECT * FROM NW_WORLD;";
        $result = mysql_query($query, $con);


        while($data = mysql_fetch_assoc($result)**)**
        {

            echo "village: $data[village]";
            echo "player: $data[player]<br>";
        }
Sign up to request clarification or add additional context in comments.

3 Comments

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I forgot a ) its the one surrounded by ) also take them out when you put it in.
oh i know try this instead of $data['village'] use $data[village] no ' or you can use echo "player:". $data['player']."<br>";
1

Generally, I only use mysql_result if I'm extracting a field from a one-column one-row (1x1) result. If you have multiple columns and/or multiple rows, I would advise you to use mysql_fetch_assoc instead.

Comments

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.