The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
sql query coding question to select and/or update userfield
Need some help with writing a query to check the condition of two userfields in vbulletin after a user has uploaded photos in photopost. This query will be in a photopost php file (the file used just after a user has finished uploading). The photopost tables and the vbulletin tables are in the same database (makes it a little easier).
The scenario: I have two userfields in vbulletin that if true (value = 1). field#x will display a link to that users photo gallery in the postbit and the member profile. field#xx will dispay the last photo uploaded as a thumbnail in the users' postbit with a link to that users' photo. Both of these are now user sectable in the user options (UserCP), and in the Admin user menu, but I would like this to be set automatically when the user uploads. If this is the first time a user has uploaded photos, then the two values of these fields will be ' ' (null). But if the user has previously uploaded then most likely these values will be '1' (true). Most likely already set by me or the user. So the first step is to check for the values of both fields. Then, based on their conditions, set or don't set the new value The varible for the uploading user in the photopost script is $upuserid. $userid is the variable (PRIMARY KEY) used by vbulletin in the userfield table. This is what I have so far, but I'm stuck on the the two 'if' conditionals. And should I use UPDATE or INSERT INTO Also, in the pohotopost scripting, they use - ppmysql_query - instead of mysql_query. Should I use the same syntax to query the vbulletin table. PHP Code:
John |
#2
|
|||
|
|||
You can replace the whole code block above with 1 line:
PHP Code:
|
#3
|
||||
|
||||
Hi MarcoH64,
So, regardless if the value of both fields is already - '1' -, this will just overwrite? PHP Code:
|
#4
|
|||
|
|||
Yes, this just tells MySQL to change these fields to the value you supply, regardless of their previous value.
|
#5
|
||||
|
||||
Odd, didn't work. I used my id as a test. I first went to my UserCp and unchecked (set to null) those two field options. Went into the database to view the change in the userfield table. My two fields, fieldx and fieldxx where indeed null. I then went and uploaded a test image in photopost. Everything went fine. No sql or php errors generated, so I assume that the syntax of the UPDATE query is correct. However, I went back to the database, but the two field values were still null, no value (1) was set. So, it seems that query was not executed.
Here's the block of code at the end of the photopost upload script, with my UPDATE query included: PHP Code:
BTW, Thank you for the time you are taking to assist me, John |
#6
|
|||
|
|||
And where did you execute $query?
|
#7
|
||||
|
||||
Quote:
The user has just uploaded photo(s). The next steps: If this is the first time he has uploaded photo(s), the existing values are null, then set the two userfields (x and xx) for this user to a value of 1 (a vbulletin table) If he has uploaded photo(s) before then do not set the two userfields, as they are already set to the value of 1, or maybe just overwrite. The remaining steps in this script are (these lines of code were already in the original photopost script): increase user post count in the vbulletin user postcount? -yes, no (a vbulletin table) notify section of code (subscription). If the user wants an email if someone comments on one of their photos (photopost tables) End of script |
#8
|
|||
|
|||
Try addingthe following after the first line:
PHP Code:
|
#9
|
||||
|
||||
BINGO!!! :up: :classic:
Did the trick. Did a bunch of test uploads, using different conditions (upload as me, upload for another user, with the two values set as null, both set as 1, etc) Works like a charm! Thank you very much for your help MarcoH64. I'm going to post this over at Photopost (with kudos to you). There are other vbulletin owners with photopost integration (or photopost owners with vbulletin integration depending on your point of view), that have similar conditions and would certainly be interested in having this block of code. Again, Much thanks John |
#10
|
|||
|
|||
We would prefer if you (also) posted your hack here on vbulletin.org and put a link to here on photopost. But htat is your own choice.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|