Connecting Tech Pros Worldwide Forums | Help | Site Map

function problem

Martoni
Guest
 
Posts: n/a
#1: Jul 17 '05
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_entitlement).

function Count_licenses($sID)
{
global $adb,$bgcl,$bgcd, $free;
$query = "SELECT * FROM software_licenses 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_entitlement=0;
for ($i=0;$i<$numRows;$i++) {
$record = $sth->fetchrow_hash();
$total_entitlement+= $record[entitlement];
}
}else {
$total_entitlement = "Not applicable";
}
$sth->finish();
} else
{
PRINT "Could not prepare query: ".$sth->errstr."<BR>\n";
}
return $total_entitlement;
}


/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
Guest
 
Posts: n/a
#2: Jul 17 '05

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_entitlement).[/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/

Martoni
Guest
 
Posts: n/a
#3: Jul 17 '05

re: function problem


It never returns a value of total_entitlement 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
Pedro Graca
Guest
 
Posts: n/a
#4: Jul 17 '05

re: function problem


Martoni wrote:[color=blue]
> function Count_licenses($sID)
> {
> global $adb,$bgcl,$bgcd, $free;
> $query = "SELECT * FROM software_licenses 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_entitlement=0;
> for ($i=0;$i<$numRows;$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 :
Jeffrey Silverman
Guest
 
Posts: n/a
#5: Jul 17 '05

re: function problem


On Tue, 23 Mar 2004 19:43:42 +0000, Martoni wrote:
[color=blue]
> It never returns a value of total_entitlement 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/

Martoni
Guest
 
Posts: n/a
#6: Jul 17 '05

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
Closed Thread