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

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


Ok, I've been working this out but I'm not sure if this is the best
way, especially with the SQL to tackle this problem (or if it will
even work).

At the end of a process, I have to run through this dynamic table I
built, and use the values within to update another existing table.

Here is the code:
-----------------------------------------
$uid  = $_GET["uid"];
$result = "SELECT pid, qty FROM $name";
while(!mysql_numrows(@mysql_query($result)))
{
   $row = mysql_fetch_array($result);
   $pid = $row["pid"];
   $qty = $row["qty"];

   $sql = "UPDATE registry SET
            bought = bought + $qty
           WHERE
            prodtempID = '$pid' AND reguserID = '$uid'";

   //exectute $sql,etc.
}
------------------------------------------
Question 1) Is this a good way with PHP to loop through my result set
(I need to hit every row) or there a better way with some kind of FOR
loop?

Question 2) In my SQL, I need what I *think* is called an aggregate
value(?). I need to take the $qty value and ADD it to the bought
value that already exists for that row. I don't think my SQL is
correct there though...

TIA

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