1
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id = '".$id."' ");
while($rows = mysql_fetch_array($data))
{ 
 $pkmn_id = $rows['pkmn_id'];
 $path = mysql_query(" SELECT path FROM pokemons WHERE pk_id = '".$pkmn_id."' ");
 $poke = mysql_result($path, 0, "path");
 echo $poke; 
 echo "<br />";
 $level = $rows['level']; 
 echo $level;
 echo "<br />";
 $exp = $rows['exp']; 
 echo $exp;

This is my PHP code, its showing an error: Array to string conversion in C:\wamp\www\slots.php on line 18

Line 18 is this:while($rows = mysql_fetch_array($data)) 

I haven't used any array?? but this used to work! but suddenly this error started coming??

5
  • Walk through the code in a debugger, inspect the variable values on each line... Commented Apr 19, 2014 at 3:43
  • what does $id consist? Commented Apr 19, 2014 at 3:43
  • How are you setting $id that is in you query? Is it possible that it is an array and not a string/integer. Commented Apr 19, 2014 at 3:43
  • Stop using mysql_ functions and use PDO. Also don't interpolate variables into SQL queries. Commented Apr 19, 2014 at 3:46
  • $id is an array! I want to convert it into a variable!?? how can i do that? Commented Apr 19, 2014 at 3:46

1 Answer 1

3

Check if $id is an array, it seems that it causes this problem.

$id = "'" . implode("', '", $id) . "'";
$data = mysql_query(" SELECT * FROM user_pokemon_db WHERE user_id IN ({$id}) ");
Sign up to request clarification or add additional context in comments.

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.