clay1 Posted September 3, 2009 Share Posted September 3, 2009 I am having some difficulty wrapping my head around this. I want to select a single value from a table for example: pg_query($conn, "select email from markets where market = richmond"); I want to assign that to variable $email pg_query gives me resource id #9 What do I need to do to get assign the email to the variable? Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/ Share on other sites More sharing options...
Zane Posted September 3, 2009 Share Posted September 3, 2009 what have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/#findComment-911338 Share on other sites More sharing options...
clay1 Posted September 3, 2009 Author Share Posted September 3, 2009 I haven't made it past the pg_query I tried $email = pg_query(....) but when I echo it I just get resource id #9 Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/#findComment-911339 Share on other sites More sharing options...
Zane Posted September 3, 2009 Share Posted September 3, 2009 This is straight from the manual for pg_query Example #1 pg_query() example . . . . . $result = pg_query($conn, "SELECT author, email FROM authors"); if (!$result) { echo "An error occured.\n"; exit; } while ($row = pg_fetch_row($result)) { echo "Author: $row[0] E-mail: $row[1]"; echo " \n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/#findComment-911343 Share on other sites More sharing options...
clay1 Posted September 3, 2009 Author Share Posted September 3, 2009 I need a loop for a single field from a single row? Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/#findComment-911382 Share on other sites More sharing options...
Zane Posted September 3, 2009 Share Posted September 3, 2009 not if you don't want a loop just do it once if that's all you need to do it..you're the coder Quote Link to comment https://forums.phpfreaks.com/topic/172915-solved-selecting-a-single-field-from-a-row-and-assign-it-to-a-variable/#findComment-911388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.