Re: Weird update problem..

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

 



Ryan S wrote:
> This is really weird... i have tried the same exact code in phpmyadmin and it works like a charm, but when i run the script... no errors then i go to phpmyadmin and nothing has changed :(
> 
> this is the code:
> ============================================================================
> $how_many_to_update=count($cardno_array);
> 
> // update the cards status to sent
> for($i=0;$i<$how_many_to_update;$i++)
> {
> $update_sql="update greetings set is_sent=1 where  cardno='".$cardno_array[$i]."' and rand_str='".$rand_str_array[$i]."' LIMIT 1";
> 
> $result = mysql_query($sql_1);

You're running the wrong query.

You're building a query in "$update_sql" but running something else.

Change the mysql_query($sql_1) line and you should be right to go.


> Slightly OT, any better way to run the multiple updates needed above than instead of running the update query in a loop?
> I searched google and the best i could find was the IN() for mySql... but that does not take 2 parameters (eg: cardno and rand_str) it would work just on card_no like this in('14','34')

An IN() clause is the same as:

field='x' or field='y'

so you can use that:

update greetings set is_sent=1 where cardno='a' or cardno='b'

if you need the extra stuff (about the rand_str) you should be able to:

update greetings set is_sent=1 where (cardno='a' and rand_str='a') or
(cardno='b' and rand_str='b')

Try it with some test data first obviously.


Some of the comments here:

http://dev.mysql.com/doc/refman/5.0/en/update.html

Provide other suggestions.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux