Bikkebakke Posted February 9, 2010 Share Posted February 9, 2010 So, sorry for asking such a simple question but I couldn't find any info on what causes this or what did I do wrong. Heres my code: $monsterID = rand(10,10); $monster = mysql_query("SELECT name FROM monsters WHERE id = 'like {$mosnterID}'"); And: echo "You encounter {$monster}"; Shows as: You encounter Resource id #4 I want it to return the name of the monster by looking up the ID of the monster. Is it my db table or is the mysql_query invalid or something? Thanks in advance and sorry for bothering you. Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/ Share on other sites More sharing options...
ram4nd Posted February 9, 2010 Share Posted February 9, 2010 Go look for some mysql php tutorials. You mysql_query returns array. You can see in it with print_r Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009588 Share on other sites More sharing options...
Bikkebakke Posted February 9, 2010 Author Share Posted February 9, 2010 I've read trough a few good tutorials over the week I've been studying PHP/MySQL but didn't find help, that's why I'm asking for some. You know it's hard to find a solution to a problem if you don't know where the problem is. Thanks for the answer, even if it doesn't help me at all. (Rather than telling whats happening you could tell whats the issue here) Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009591 Share on other sites More sharing options...
Bikkebakke Posted February 9, 2010 Author Share Posted February 9, 2010 Also, in the code: $monster = mysql_query("SELECT name FROM monsters WHERE id = 'like {$mosnterID}'"); {$mosnterID} is typoed, it is monsterID, that's not the problem. Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009595 Share on other sites More sharing options...
Bikkebakke Posted February 9, 2010 Author Share Posted February 9, 2010 Okay I figured it out myself: $monsterID = rand(10,10); $monsterquery = mysql_query("SELECT * FROM monsters WHERE id = $monsterID"); $monster = mysql_fetch_array($monsterquery); and: echo "You encounter {$monster['name']}"; Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009619 Share on other sites More sharing options...
aeroswat Posted February 9, 2010 Share Posted February 9, 2010 You encounter resource ID #4... sounds scary Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009626 Share on other sites More sharing options...
ram4nd Posted February 10, 2010 Share Posted February 10, 2010 try something like $monsterID = 10; $monsterquery = mysql_query('SELECT * FROM monsters WHERE id = '.$monsterID); $monster = mysql_fetch_array($monsterquery); foreach($monster as $row) echo row['id']; Link to comment https://forums.phpfreaks.com/topic/191517-a-little-problem-quick-to-fix/#findComment-1009898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.