Getting value from existing query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • none

    Getting value from existing query

    Hi all, now if I've understood the code below correctly, if I add the
    line;

    $session_dean_i d = $hResult('dean_ id');

    At the bottom I will create a new variable named '$session_dean_ id'
    which will have the value grabbed from the table 'iUser' from the
    'dean_id' column. Am i right or way off?

    Many thanks


    $sQuery = "
    Select iUser, dean_id
    From tblUsers
    Where sGUID = '$sGUID'";
    $hResult = mysql_query($sQ uery, $hDB);
    if(!mysql_affec ted_rows($hDB)) {
    // No match for guid
    header('Locatio n: ../login.php?refer ='.urlencode($P HP_SELF.'?'.$HT TP_SERVER_VARS['QUERY_STRING']));
    }
  • Jan Pieter Kunst

    #2
    Re: Getting value from existing query

    In article <863d38a1.04042 10313.278df977@ posting.google. com>,
    kinskai@aol.com (none) wrote:
    [color=blue]
    > Hi all, now if I've understood the code below correctly, if I add the
    > line;
    >
    > $session_dean_i d = $hResult('dean_ id');
    >
    > At the bottom I will create a new variable named '$session_dean_ id'
    > which will have the value grabbed from the table 'iUser' from the
    > 'dean_id' column. Am i right or way off?
    >
    > Many thanks
    >
    >
    > $sQuery = "
    > Select iUser, dean_id
    > From tblUsers
    > Where sGUID = '$sGUID'";
    > $hResult = mysql_query($sQ uery, $hDB);
    > if(!mysql_affec ted_rows($hDB)) {
    > // No match for guid
    > header('Locatio n:
    > ../login.php?refer ='.urlencode($P HP_SELF.'?'.$HT TP_SERVER_VARS['QUERY_STRING']
    > ));
    > }[/color]


    No, it should be:

    if (mysql_num_rows ($hResult) == 0) {

    // mysql_num_rows is for SELECT queries
    // mysql_affected_ rows for UPDATE, INSERT and DELETE queries

    // no match for guid

    } else {

    list($iuser, $session_dean_i d) = mysql_fetch_row ($hResult);
    }

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • none

      #3
      Re: Getting value from existing query

      Jan Pieter Kunst <devnull@cauce. org> wrote in message news:<devnull-231B93.19582521 042004@news1.ne ws.xs4all.nl>.. .[color=blue]
      > In article <863d38a1.04042 10313.278df977@ posting.google. com>,
      > kinskai@aol.com (none) wrote:
      >[color=green]
      > > Hi all, now if I've understood the code below correctly, if I add the
      > > line;
      > >
      > > $session_dean_i d = $hResult('dean_ id');
      > >
      > > At the bottom I will create a new variable named '$session_dean_ id'
      > > which will have the value grabbed from the table 'iUser' from the
      > > 'dean_id' column. Am i right or way off?
      > >
      > > Many thanks
      > >
      > >
      > > $sQuery = "
      > > Select iUser, dean_id
      > > From tblUsers
      > > Where sGUID = '$sGUID'";
      > > $hResult = mysql_query($sQ uery, $hDB);
      > > if(!mysql_affec ted_rows($hDB)) {
      > > // No match for guid
      > > header('Locatio n:
      > > ../login.php?refer ='.urlencode($P HP_SELF.'?'.$HT TP_SERVER_VARS['QUERY_STRING']
      > > ));
      > > }[/color]
      >
      >
      > No, it should be:
      >
      > if (mysql_num_rows ($hResult) == 0) {
      >
      > // mysql_num_rows is for SELECT queries
      > // mysql_affected_ rows for UPDATE, INSERT and DELETE queries
      >
      > // no match for guid
      >
      > } else {
      >
      > list($iuser, $session_dean_i d) = mysql_fetch_row ($hResult);
      > }
      >
      > JP[/color]


      Right, i'm a little lost. The query code I grabbed from a login script
      which checks if the user is logged in when accessing the page. I
      wanted to get the 'dean_id' value at the same time this is happening
      on each page by 'dean_id' to the query and creating a new variable
      from it.

      Are you saying then that the code I have used from an example I saw on
      the net is wrong?

      Many thanks.

      Comment

      • Jan Pieter Kunst

        #4
        Re: Getting value from existing query

        In article <863d38a1.04042 20753.481602a4@ posting.google. com>,
        kinskai@aol.com (none) wrote:
        [color=blue]
        > Are you saying then that the code I have used from an example I saw on
        > the net is wrong?[/color]

        What I'm saying is that in this code fragment:

        $sQuery = "
        Select iUser, dean_id
        From tblUsers
        Where sGUID = '$sGUID'";

        $hResult = mysql_query($sQ uery, $hDB);

        if(!mysql_affec ted_rows($hDB)) {

        }

        mysql_affected_ rows() is not used correctly. See
        <http://nl.php.net/manual/en/function.mysql-affected-rows.php> for the
        official word.

        JP

        --
        Sorry, <devnull@cauce. org> is een "spam trap".
        E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

        Comment

        Working...