[thelist] is this correct PHP/SQL or a better way? [solved]

Tom Dell'Aringa pixelmech at yahoo.com
Tue Jan 7 16:11:01 CST 2003


--- Kelly Hallman <khallman at wrack.org> wrote:
> On Tue, 7 Jan 2003, Tom Dell'Aringa wrote:
> > Here is the code:
>
> Modified your while loop:
> -----------------------------------------
> $uid  = $_GET["uid"];
> $sqlquery = "SELECT pid, qty FROM $name";
> $qres = mysql_query($sqlquery);
> while($row = mysql_fetch_array($qres))) {
>     $pid = $row["pid"];
>     $qty = $row["qty"];
>
>     $sql = "UPDATE registry SET bought = bought + $qty
>         WHERE prodtempID = '$pid' AND reguserID = '$uid'";
> }
>
> > ------------------------------------------
> > Question 1) Is there a better way with some kind of FOR loop?
>
> I modified your code above..  I don't think
> !mysql_numrows(@mysql_query($q)) is a good while condition because
> it's
> going to continuously evalute to true, as long as you have rows in
> the
> result.  Better to fetch the array as your while condition.  When
> there
> are no more result rows, it will return false ending the while
> loop..

Thanks Kelly, I forgot that the rows would always be there!

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the thelist mailing list