function problem

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

    function problem

    Can anyone see what's wrong with this function? Running the query directly in MySQL produces correct results (ie a value for free and total_entitleme nt).

    function Count_licenses( $sID)
    {
    global $adb,$bgcl,$bgc d, $free;
    $query = "SELECT * FROM software_licens es WHERE (sID = '$sID')";
    $sth = $adb->prepare($query );
    if($sth)
    {
    $res = $sth->execute();
    $numRows = $sth->rows();
    $record = $sth->fetchrow_hash( );
    $free = $record[free];
    if($free = "No" || $free = ""){
    $total_entitlem ent=0;
    for ($i=0;$i<$numRo ws;$i++) {
    $record = $sth->fetchrow_hash( );
    $total_entitlem ent+= $record[entitlement];
    }
    }else {
    $total_entitlem ent = "Not applicable";
    }
    $sth->finish();
    } else
    {
    PRINT "Could not prepare query: ".$sth->errstr."<BR>\n ";
    }
    return $total_entitlem ent;
    }


    /M.
    --
    Martin Skjöldebrand
    Family site: http://www.skjoldebrand.org
    "Art" site: http://martoni.deviantart.com
    Public key available at: http://wwwkeys.pgp.net
  • Jeffrey Silverman

    #2
    Re: function problem

    On Mon, 22 Mar 2004 20:43:38 +0000, Martoni wrote:
    [color=blue]
    > Can anyone see what's wrong with this function? Running the query
    > directly in MySQL produces correct results (ie a value for free and
    > total_entitleme nt).[/color]

    Um, what is wrong with it? (I'm not gonna wade through it without some
    more info)

    Error messages?

    --
    Jeffrey D. Silverman | jeffrey AT jhu DOT edu
    Website | http://www.wse.jhu.edu/newtnotes/

    Comment

    • Martoni

      #3
      Re: function problem

      It never returns a value of total_entitleme nt other than 0.

      /M.
      --
      Martin Skjöldebrand
      Family site: http://www.skjoldebrand.org
      "Art" site: http://martoni.deviantart.com
      Public key available at: http://wwwkeys.pgp.net

      Comment

      • Pedro Graca

        #4
        Re: function problem

        Martoni wrote:[color=blue]
        > function Count_licenses( $sID)
        > {
        > global $adb,$bgcl,$bgc d, $free;
        > $query = "SELECT * FROM software_licens es WHERE (sID = '$sID')";
        > $sth = $adb->prepare($query );
        > if($sth)
        > {
        > $res = $sth->execute();
        > $numRows = $sth->rows();
        > $record = $sth->fetchrow_hash( );
        > $free = $record[free];
        > if($free = "No" || $free = ""){[/color]
        Uh Oh!
        assignment, not comparison ... what do you expect the contents of $free
        to be after this statement?
        [color=blue]
        > $total_entitlem ent=0;
        > for ($i=0;$i<$numRo ws;$i++) {
        > $record = $sth->fetchrow_hash( );[/color]
        Uh Oh!
        read a second row and disregard the first?
        It doesn't seem a good idea, especially when the second row is empty and
        you don't test it.


        --
        USENET would be a better place if everybody read: : mail address :
        http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
        http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
        http://www.expita.com/nomime.html : to 10K bytes :

        Comment

        • Jeffrey Silverman

          #5
          Re: function problem

          On Tue, 23 Mar 2004 19:43:42 +0000, Martoni wrote:
          [color=blue]
          > It never returns a value of total_entitleme nt other than 0.
          >
          > /M.[/color]

          it looks like Pedro Garcia has provided clues for you.

          == is NOT the same as =


          later...
          --
          Jeffrey D. Silverman | jeffrey AT jhu DOT edu
          Website | http://www.wse.jhu.edu/newtnotes/

          Comment

          • Martoni

            #6
            Re: function problem

            Ok, thanks.
            I've been looking at for too long. Needed another pair of eyes....

            /M.
            --
            Martin Skjöldebrand
            Family site: http://www.skjoldebrand.org
            "Art" site: http://martoni.deviantart.com
            Public key available at: http://wwwkeys.pgp.net

            Comment

            Working...