chrisuk Posted September 9, 2008 Share Posted September 9, 2008 I must be doing something really silly here, I am trying to get the players ID from their name based on selection from a dropdown menu: $winner = $_POST['winner']; $sql = "SELECT player_id FROM players WHERE player = '$winner'"; $result = mysql_query($sql)or die("error"); echo $sql; echo $result; $player_id = $player_id; echo $player_id; The output of the echos is: SELECT player_id FROM players WHERE player = 'Joe "Nickname" Bloggs'id #3 So the select statement is picking up the name, but why is it not getting the player id? I thought using the quotes would be athe probem so tried just "bloggs" - same problem Thanks in advance.. Link to comment https://forums.phpfreaks.com/topic/123445-solved-whats-wrong-with-this-select-statement/ Share on other sites More sharing options...
akitchin Posted September 9, 2008 Share Posted September 9, 2008 mysql_query() just returns a resource id which points to your resultset. you need to use an extraction function such as mysql_fetch_assoc() on that resource to retrieve the records. have a look at a basic php/mysql tutorial to learn the difference and the different types of extraction functions that exist. i believe there's one on the main phpfreaks website even. Link to comment https://forums.phpfreaks.com/topic/123445-solved-whats-wrong-with-this-select-statement/#findComment-637553 Share on other sites More sharing options...
lanmonkey Posted September 9, 2008 Share Posted September 9, 2008 try this: $winner = $_POST['winner']; $sql = "SELECT player_id FROM players WHERE player = '$winner'"; $result = mysql_query($sql)or die("error"); $player_details = mysql_fetch_assoc($result); $player_id = $player_details['player_id']; echo $player_id; Link to comment https://forums.phpfreaks.com/topic/123445-solved-whats-wrong-with-this-select-statement/#findComment-637562 Share on other sites More sharing options...
chrisuk Posted September 9, 2008 Author Share Posted September 9, 2008 Thankyou very much guys, that's solved it! I should have known about extraction...I'm very rusty Cheers Link to comment https://forums.phpfreaks.com/topic/123445-solved-whats-wrong-with-this-select-statement/#findComment-637786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.