Re: Help please

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From original msg:
>> I need to be able to do is increment an mysql database field each time an
DN> =possibly an AUTO_INCREMENT field is what is needed here

Is that what he has been trying to do? I think SpiderWebb needed to see
how many pieces of the item were sold, didnt'he?

So let's say he's got a table like:
--------------
 TABLE: items
--------------
 id
 item_name
 sales_rank
-------------

Now everytime the order is placed, he needs to query the DB 2
times:

// Find out the former sales rank:
$sql = "SELECT sales_rank FROM items WHERE id = $item_id_just_sold";
$result = @MySQL_Query( $sql );
$record = MySQL_Fetch_Array( $result );
$new_sales_rank = $record["sales_rank"] + $pcs_just_ordered;

// Update the field:
$sql = "UPDATE items SET sales_rank = $new_sales_rank
        WHERE id = $item_id_just_sold";
$result = @MySQL_Query( $sql );
if ( $result && ( MySQL_Num_Rows() == 1 ) ):
   echo "Successfully updated..."; // It's better to redirect him somewhere else...
                                   // ...to prevent 'after-refresh' issues...
endif;

------------------

Is that what you wanted?

More great sources:
www.phpbuilder.com
www.webmonkey.com
www.hotscripts.com
www.google.com ----> this one is the best, try it!!!! It finds everything.


Good luck.

Michal Stankoviansky
-----------------------------------------


>> item is sold then look at that field to decide which price variable to
DN> write
>> to the price field of the database. Could someone point me in the right
>> direction where I could solve this or to someone who could

DN> =when you say "database" twice, can I assume you are talking about two
DN> different tables?

DN> =if the user has identified the product, then presumably (s)he has also
DN> mentioned an order quantity. Thus the easiest thing to do is to query the
DN> whole price row from the tbl and make the price-rate choice using your
DN> program logic. However it would likely be more efficient to have MySQL do it
DN> but to comment we would need to see the tbl schema.

DN> =hope that gets you started,
DN> =dn

DN> PS: there are many tutorials available covering the PHP/MySQL combination.
DN> Check with the product home sites and follow links to likely sources.




-------------------------------------------------------


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux