Finding the results of a query

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

    Finding the results of a query

    I am working on a script that will query a database for a FNAME/LNAME
    combo. If it finds the combo, I need it to do one set of instructions.
    If it doesn't find it, I need it to do something else. What I can't
    figure out is what variable to check against. Here is what I have for
    the relevant part of the script:

    $connection = mysql_connect($ hostname, $username, $password);
    mysql_select_db ($databasename) or die ("Cannot connect to database"
    ..mysql_error() );
    $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
    NAME=('$LName') ";
    $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
    mysql_close($co nnection);

    I tried checking the value of $result to see if it changed depending on
    whether or not it found the selection. It does not. I just can't figure
    out what to use for:

    if (some expression){
    perform this code
    }
    else{
    do this
    }

  • Jerim79

    #2
    Re: Finding the results of a query


    Jerim79 wrote:
    I am working on a script that will query a database for a FNAME/LNAME
    combo. If it finds the combo, I need it to do one set of instructions.
    If it doesn't find it, I need it to do something else. What I can't
    figure out is what variable to check against. Here is what I have for
    the relevant part of the script:
    >
    $connection = mysql_connect($ hostname, $username, $password);
    mysql_select_db ($databasename) or die ("Cannot connect to database"
    .mysql_error()) ;
    $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
    NAME=('$LName') ";
    $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
    mysql_close($co nnection);
    >
    I tried checking the value of $result to see if it changed depending on
    whether or not it found the selection. It does not. I just can't figure
    out what to use for:
    >
    if (some expression){
    perform this code
    }
    else{
    do this
    }
    I guess I could load the results into an array using fetchrow(), and
    then check to see if it is NULL or contains data. If it is NULL, then
    it didn't find it and I can do one set of instructions. If it is not
    NULL, I can do another set of instructions. I am not sure that is the
    best way to do it though. I would think that $result would change on
    based on finding it or not, and I could just easily check against
    $result.

    Comment

    • Shelly

      #3
      Re: Finding the results of a query


      "Jerim79" <mylek@hotmail. comwrote in message
      news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
      >I am working on a script that will query a database for a FNAME/LNAME
      combo. If it finds the combo, I need it to do one set of instructions.
      If it doesn't find it, I need it to do something else. What I can't
      figure out is what variable to check against. Here is what I have for
      the relevant part of the script:
      >
      $connection = mysql_connect($ hostname, $username, $password);
      mysql_select_db ($databasename) or die ("Cannot connect to database"
      .mysql_error()) ;
      $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
      NAME=('$LName') ";
      $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
      mysql_close($co nnection);
      >
      I tried checking the value of $result to see if it changed depending on
      whether or not it found the selection. It does not. I just can't figure
      out what to use for:
      >
      if (some expression){
      perform this code
      }
      else{
      do this
      }
      >
      $numRows = mysql_num_rows( $result);

      then test on whether $numRows is greater than zero.

      Shelly


      Comment

      • Jerim79

        #4
        Re: Finding the results of a query


        Shelly wrote:
        "Jerim79" <mylek@hotmail. comwrote in message
        news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
        I am working on a script that will query a database for a FNAME/LNAME
        combo. If it finds the combo, I need it to do one set of instructions.
        If it doesn't find it, I need it to do something else. What I can't
        figure out is what variable to check against. Here is what I have for
        the relevant part of the script:

        $connection = mysql_connect($ hostname, $username, $password);
        mysql_select_db ($databasename) or die ("Cannot connect to database"
        .mysql_error()) ;
        $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
        NAME=('$LName') ";
        $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
        mysql_close($co nnection);

        I tried checking the value of $result to see if it changed depending on
        whether or not it found the selection. It does not. I just can't figure
        out what to use for:

        if (some expression){
        perform this code
        }
        else{
        do this
        }
        >
        $numRows = mysql_num_rows( $result);
        >
        then test on whether $numRows is greater than zero.
        >
        Shelly
        Thanks, that worked perfectly. Now I need to take the first name and
        the last name out of the query result and convert them to lower case. I
        understand there is a PHP function for lower case. My question is how
        to access specific columns in the result.

        Comment

        • strawberry

          #5
          Re: Finding the results of a query


          Jerim79 wrote:
          Shelly wrote:
          "Jerim79" <mylek@hotmail. comwrote in message
          news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
          >I am working on a script that will query a database for a FNAME/LNAME
          combo. If it finds the combo, I need it to do one set of instructions.
          If it doesn't find it, I need it to do something else. What I can't
          figure out is what variable to check against. Here is what I have for
          the relevant part of the script:
          >
          $connection = mysql_connect($ hostname, $username, $password);
          mysql_select_db ($databasename) or die ("Cannot connect to database"
          .mysql_error()) ;
          $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
          NAME=('$LName') ";
          $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
          mysql_close($co nnection);
          >
          I tried checking the value of $result to see if it changed depending on
          whether or not it found the selection. It does not. I just can't figure
          out what to use for:
          >
          if (some expression){
          perform this code
          }
          else{
          do this
          }
          >
          $numRows = mysql_num_rows( $result);

          then test on whether $numRows is greater than zero.

          Shelly
          >
          Thanks, that worked perfectly. Now I need to take the first name and
          the last name out of the query result and convert them to lower case. I
          understand there is a PHP function for lower case. My question is how
          to access specific columns in the result.

          SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
          FROM (table)
          WHERE FNAME=('$FName' )
          AND
          NAME=('$LName')

          Comment

          • Jerim79

            #6
            Re: Finding the results of a query


            strawberry wrote:
            Jerim79 wrote:
            >
            Shelly wrote:
            "Jerim79" <mylek@hotmail. comwrote in message
            news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
            I am working on a script that will query a database for a FNAME/LNAME
            combo. If it finds the combo, I need it to do one set of instructions.
            If it doesn't find it, I need it to do something else. What I can't
            figure out is what variable to check against. Here is what I have for
            the relevant part of the script:

            $connection = mysql_connect($ hostname, $username, $password);
            mysql_select_db ($databasename) or die ("Cannot connect to database"
            .mysql_error()) ;
            $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
            NAME=('$LName') ";
            $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
            mysql_close($co nnection);

            I tried checking the value of $result to see if it changed depending on
            whether or not it found the selection. It does not. I just can't figure
            out what to use for:

            if (some expression){
            perform this code
            }
            else{
            do this
            }

            >
            $numRows = mysql_num_rows( $result);
            >
            then test on whether $numRows is greater than zero.
            >
            Shelly
            Thanks, that worked perfectly. Now I need to take the first name and
            the last name out of the query result and convert them to lower case. I
            understand there is a PHP function for lower case. My question is how
            to access specific columns in the result.
            >
            >
            SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
            FROM (table)
            WHERE FNAME=('$FName' )
            AND
            NAME=('$LName')
            I tried that and it didn't seem to work. I am converting my FName and
            LName as they are posted from the form page.
            $FName=strtolow er($_POST["$FName"])

            That seemed to work, as valid data was returning negative results
            before making the changes you suggested. So now I just need to get the
            SQL results into lower case. I am curious as to lc_fname and lc_lname.
            Are those new variable names that I should check against or do they
            replace FNAME automatically?

            Comment

            • strawberry

              #7
              Re: Finding the results of a query


              Jerim79 wrote:
              strawberry wrote:
              Jerim79 wrote:
              Shelly wrote:
              "Jerim79" <mylek@hotmail. comwrote in message
              news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
              >I am working on a script that will query a database for a FNAME/LNAME
              combo. If it finds the combo, I need it to do one set of instructions.
              If it doesn't find it, I need it to do something else. What I can't
              figure out is what variable to check against. Here is what I have for
              the relevant part of the script:
              >
              $connection = mysql_connect($ hostname, $username, $password);
              mysql_select_db ($databasename) or die ("Cannot connect to database"
              .mysql_error()) ;
              $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
              NAME=('$LName') ";
              $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
              mysql_close($co nnection);
              >
              I tried checking the value of $result to see if it changed depending on
              whether or not it found the selection. It does not. I just can't figure
              out what to use for:
              >
              if (some expression){
              perform this code
              }
              else{
              do this
              }
              >

              $numRows = mysql_num_rows( $result);

              then test on whether $numRows is greater than zero.

              Shelly
              >
              Thanks, that worked perfectly. Now I need to take the first name and
              the last name out of the query result and convert them to lower case. I
              understand there is a PHP function for lower case. My question is how
              to access specific columns in the result.

              SELECT lower(FNAME) lc_fname, lower(LNAME) lc_lname
              FROM (table)
              WHERE FNAME=('$FName' )
              AND
              NAME=('$LName')
              >
              I tried that and it didn't seem to work. I am converting my FName and
              LName as they are posted from the form page.
              $FName=strtolow er($_POST["$FName"])
              >
              That seemed to work, as valid data was returning negative results
              before making the changes you suggested. So now I just need to get the
              SQL results into lower case. I am curious as to lc_fname and lc_lname.
              Are those new variable names that I should check against or do they
              replace FNAME automatically?
              They're just aliases.

              SELECT FNAME, lower(FNAME) AS lc_fname, LNAME, lower(LNAME) AS lc_lname
              FROM (table)
              WHERE FNAME=('$FName' )
              AND
              NAME=('$LName')

              is 'NAME' right on the last line?

              This should work. Although php is case sensitive, mysql isn't - unless
              you include BINARY in the query- so I can't quite see why you need to
              do all that stuff.

              Comment

              • Shelly

                #8
                Re: Finding the results of a query


                "Jerim79" <mylek@hotmail. comwrote in message
                news:1164130117 .634974.266300@ m7g2000cwm.goog legroups.com...
                >
                Shelly wrote:
                >"Jerim79" <mylek@hotmail. comwrote in message
                >news:116412474 3.834016.303130 @m73g2000cwd.go oglegroups.com. ..
                >I am working on a script that will query a database for a FNAME/LNAME
                combo. If it finds the combo, I need it to do one set of instructions.
                If it doesn't find it, I need it to do something else. What I can't
                figure out is what variable to check against. Here is what I have for
                the relevant part of the script:
                >
                $connection = mysql_connect($ hostname, $username, $password);
                mysql_select_db ($databasename) or die ("Cannot connect to database"
                .mysql_error()) ;
                $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
                NAME=('$LName') ";
                $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
                mysql_close($co nnection);
                >
                I tried checking the value of $result to see if it changed depending on
                whether or not it found the selection. It does not. I just can't figure
                out what to use for:
                >
                if (some expression){
                perform this code
                }
                else{
                do this
                }
                >
                >>
                >$numRows = mysql_num_rows( $result);
                >>
                >then test on whether $numRows is greater than zero.
                >>
                >Shelly
                >
                Thanks, that worked perfectly. Now I need to take the first name and
                the last name out of the query result and convert them to lower case. I
                understand there is a PHP function for lower case. My question is how
                to access specific columns in the result.
                $row = mysql_fetch_ass oc($result);
                $lastName = strtolower($row['LNAME']);
                $firstName = strtolower($row 'FNAME']);

                Shelly


                Comment

                • Jerim79

                  #9
                  Re: Finding the results of a query


                  Shelly wrote:
                  "Jerim79" <mylek@hotmail. comwrote in message
                  news:1164130117 .634974.266300@ m7g2000cwm.goog legroups.com...

                  Shelly wrote:
                  "Jerim79" <mylek@hotmail. comwrote in message
                  news:1164124743 .834016.303130@ m73g2000cwd.goo glegroups.com.. .
                  I am working on a script that will query a database for a FNAME/LNAME
                  combo. If it finds the combo, I need it to do one set of instructions.
                  If it doesn't find it, I need it to do something else. What I can't
                  figure out is what variable to check against. Here is what I have for
                  the relevant part of the script:

                  $connection = mysql_connect($ hostname, $username, $password);
                  mysql_select_db ($databasename) or die ("Cannot connect to database"
                  .mysql_error()) ;
                  $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName' ) AND
                  NAME=('$LName') ";
                  $result = mysql_query($qu ery) or die('Query failed: ' . mysql_error());
                  mysql_close($co nnection);

                  I tried checking the value of $result to see if it changed depending on
                  whether or not it found the selection. It does not. I just can't figure
                  out what to use for:

                  if (some expression){
                  perform this code
                  }
                  else{
                  do this
                  }

                  >
                  $numRows = mysql_num_rows( $result);
                  >
                  then test on whether $numRows is greater than zero.
                  >
                  Shelly
                  Thanks, that worked perfectly. Now I need to take the first name and
                  the last name out of the query result and convert them to lower case. I
                  understand there is a PHP function for lower case. My question is how
                  to access specific columns in the result.
                  >
                  $row = mysql_fetch_ass oc($result);
                  $lastName = strtolower($row['LNAME']);
                  $firstName = strtolower($row 'FNAME']);
                  >
                  Shelly
                  Thak you for the help. I didn't have to format the MySQL data after
                  all. The data stored in the database had capital letters. However, my
                  correct data returns true no matter how I capitalize it. The wrong data
                  returns false. So it just seems to work. I didn't have to make any
                  change to the MySQL query at all. I appreciate your help on getting the
                  $_POST variables to lower case and

                  Comment

                  Working...