Set Variable to One Column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jhwrightiii@nospamatt.net

    Set Variable to One Column

    Is it possible to set a variable from a query that will return one
    row ie..

    $control = mysql_query("SE LECT control FROM table WHERE id = '1'");
  • Gordon Burditt

    #2
    Re: Set Variable to One Column

    >Is it possible to set a variable from a query that will return one[color=blue]
    >row ie..
    >
    >$control = mysql_query("SE LECT control FROM table WHERE id = '1'");[/color]

    Yes, but $control is a MySQL result handle, not the value.
    To get the value (and there are a number of different ways to do this,
    and you really need to do some error checking in case there was no
    row with id = 1):

    $r = mysql_fetch_res ult($control);
    $value = $r[0];
    /* we now have the value you wanted in $value */
    echo "$value";
    mysql_free_resu lt($control);

    Gordon L. Burditt


    Comment

    • jhwrightiii@nospamatt.net

      #3
      Re: Set Variable to One Column


      I appreciate it. I am new in PHP. I knew about the result handle and
      was just trying to show an example. In other languages I am able to
      do something similar to that example all in one line and is what I was
      aiming for. Two extra lines will do though.

      Again thanks for you Help.

      On Wed, 20 Jul 2005 21:06:58 -0000, gordonb.sf1ma@b urditt.org (Gordon
      Burditt) wrote:
      [color=blue][color=green]
      >>Is it possible to set a variable from a query that will return one
      >>row ie..
      >>
      >>$control = mysql_query("SE LECT control FROM table WHERE id = '1'");[/color]
      >
      >Yes, but $control is a MySQL result handle, not the value.
      >To get the value (and there are a number of different ways to do this,
      >and you really need to do some error checking in case there was no
      >row with id = 1):
      >
      > $r = mysql_fetch_res ult($control);
      > $value = $r[0];
      > /* we now have the value you wanted in $value */
      > echo "$value";
      > mysql_free_resu lt($control);
      >
      > Gordon L. Burditt
      >[/color]

      Comment

      Working...