vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   mysql: if similar row exists set field=1 (https://vborg.vbsupport.ru/showthread.php?t=192111)

jerx 09-28-2008 09:16 AM

mysql: if similar row exists set field=1
 
I am trying to import a buddy list into vb. Unfortunately those entries do not state friend status. Therefore I have to set it manually.

The table looks like this:
user_id contact_id user_ignore friend (=column1, column2, column3, column4)
The friend column was added by myself, because I wanted to use that for the friend status.

Now I would like to set the friend status to 1, if both users have added each other to their buddy list.

Example

If there is an entry like this
1 2 0 0
(user1 added user2 to his buddy list)

it should be turned into
1 2 0 1
(user2 is friend of user1)

if this entry exists
2 1 0 0
(user2 added user1 to his buddy list)

It would even be better to check the ignore column, too. But this would not be as important, because there are only about 100 entries which I could check manually.

Anyone able to help me on this?

Thank you in advance!

Marco van Herwaarden 09-28-2008 09:54 AM

[sql]UPDATE TABLENAME AS t1, TABLENAME AS t2
SET t1.friend = 1
WHERE t1.user_id = t2.contact_id AND t1.contact_id = t2.user_id;[/sql]
Replace TABLENAME (twice) by your tablename.

Not tested, so make backup before running this.

jerx 09-28-2008 11:25 AM

Thank you so much, Marco!

The solution is so easy and a look at the mysql manual would have revealed the solution right away (first user comment). But I never had the idea to look up the update query, because I thought I needed some fancy stuff for the second part.


All times are GMT. The time now is 01:33 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01707 seconds
  • Memory Usage 1,706KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete