Jump to content

[SOLVED] Selecting a single field from a row and assign it to a variable?


Recommended Posts

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?

 

 

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";
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.