Re: can I do this: update table while selecting data from table?
| From: | afan at afan dot net | Date: | Thu, 15 Jun 2006 00:46:16 +0000 |
| Subject: | Re: can I do this: update table while selecting data from table? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-238020@lists.php.net to get a copy of this message | ||
No, that was just an exapmle to explain better. Of course this is not the
REAL code. :)
And there are some more thing to do inside while loop.
Thanks.
-afan
> It looks very much as if you did:
>
> update members set member_name = 'N/A' where member_name = null
>
> Nevertheless, I would rather keep null within the database and use 'N/A'
> at
> the presentation level. My rule is that the data in the database
> should
> be in a machine oriented format. For example, I store timestamps, never
> formated dates, numbers as actual numerical datatypes, not as strings,
> though PHP can cope with either. 'N/A' is a way to present that
> information
> to the user, which might even be, for example, language dependant.
>
> On displaying, you could well do:
>
> SELECT member_id, ifnull(member_name,'N/A') FROM members
>
> Satyam
>
>
> ----- Original Message -----
> From: <afan@afan.net>
> To: <php-general@lists.php.net>
> Sent: Wednesday, June 14, 2006 11:37 PM
> Subject: [PHP] can I do this: update table while selecting data from
> table?
>
>
>> Am I allowde to do this:
>>
>> $query = mysql_query("SELECT member_id, member_name FROM members");
>> while($result = mysql_fetch_array($query))
>> {
>> if(empty($result['member_name']))
>> {
>> mysql_query("UPDATE members SET member_name = 'N/A' WHERE member_id =
>> ".$result['member_id']."");
>> }
>> }
>>
>> As far as I know, after "SELECT" query, data are in buffer and I AM able
>> to connect to the same table and do UPDATE, right?
>>
>> Thanks
>>
>> -afan
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>