Ryan
Feb 11 2005, 08:05 PM
I got this query... CODE <?php error_reporting(E_ALL); //Tell all the things
$host="this_host"; $user="me"; $pass="secret_word"; $users_table="users_table_for_smf"; $member_group_col="column_name_for_member_group_in_smf"; $new_group_name="whatever"; $this_group="the_old_group"; $custom_field="custom_field_in_users_profile"; $this_value="the_value_for_custom_field";
mysql_connect($host,$user,$pass) or die ("Can't connect, was told : <br>". mysql_error()); mysql_select_db('smf') or die ("Can't open database, was told : <br>".mysql_error());
$query = "UPDATE $users_table SET $member_group_col = $new_group_name "; $query .= "WHERE $member_group_col = $this_group AND "; $query .= "$custom_field = $this_value ";
mysql_query($query); print("Updated records: %d\n", mysql_affected_rows()); ?>
but i need this modified cause custom profile field data is stored in smf_themes and the membergroup data is store in smf_members with MEMBER ID as the common field, I am hoping someone here can rewrite this for me to work cause I don't know php, i had to get someone to write me this qury but they don't know how toy use the SQL Join. here is what i want this for: i need a php script to query the db, the smf users table and checks to entires in a users profile a custom field i made and the member group and if both match preset values then i want it to change the member group. i would just want this to be a php file that i can just randomly decide to goto, enter the url in firefox or any browser then it will run.
Reply
miCRoSCoPiC^eaRthLinG
Feb 11 2005, 09:38 PM
Hey Ryan, [/tab]I didn't get a really clear picture from the post, but it seems like you are trying to get a collection of different fields from a set of disjoint tables and depending on the result you intend to modify the column value of a certain table - that's almost what you term as Inner/Outer Join in SQL depending on the tables that you are combining the values from.. There are so many kinds of JOINS (Inner, Outer, Full, Cross, etc.) that if I began to to talk about them the posts would fill up all the space available on any board  [tab]But one factor that is common to almost all the joins is that you have to explicitly specify, WHICH COLUMN is being fetched from WHICH TABLE/DB, i.e., let me show you by modifying a little bit of one of your querries: QUOTE $query = "UPDATE $users_table SET $member_group_col = $new_group_name "; $query .= "WHERE $member_group_col = $this_group AND "; $query .= "$custom_field = $this_value ";
[/tab]Say, your $member_group_col resides in one table and $custom_field resides in another and the tables are titled say, A and B, your query would transform into: QUOTE $query = "UPDATE $users_table SET A." . " $member_group_col = $new_group_name "; $query .= "WHERE A." . "$member_group_col = $this_group AND "; $query .= "B." . "$custom_field = $this_value ";
---> i.e., for joins, columns from different tables (that's what join is for) aren't referred to as simply column names, but they have to be refered as, tablename.columnname in EVERY instance they occur in your query. This is a MUST. Or else, you can you aliasing, wherby you can specify a name, say Column1 = A.Column1 and Column2 = B.Column2 --> you can probably see, that these two disjoint columns can be refered in your queries as just Column1 and Column2... [tab]There's an excellent book on all this named "MySQL CookBook that teaches you all these trick 10 times over in 1000 different ways. It's written by Paul Dubois and published by O'Reilly. You should grab it rightaway. Try eBay -and you might be able to get a second hand one at about 1/10th the price.. I find it an extremely good reference at these confusing points, coz that's where it opens up a handful of really nifty tricks to solve your prob... Have fun.. Hope I could help you, even if marginally - coz even I'm relatively new to SQL - I've been messing around with it for at the most an year or so...my main background is in C++ & Java on Linux..  A useful link on JOINS: http://www.sqlteam.com/item.asp?ItemID=11122
Reply
Ryan
Feb 11 2005, 10:04 PM
right, you lost me their, have you used SMF?
Reply
miCRoSCoPiC^eaRthLinG
Feb 12 2005, 07:21 AM
Lol.. Ok.. here's the deal. I'm going to grab a copy of SMF and try it out and see if I encounter similar problem. Or else I can try to simulate the exact db/table names that you've set up and try again.. In that case you need to paste here the db and tables names that you were using and a little more details about the table colums..
Reply
Ryan
Feb 12 2005, 07:43 AM
just look at the stucture to see what type of join i need, cus i want it to if you are in group id 4 lets say and the value of this profile field (stored in themems rater than users) is say yes then i want it to change the group to say groupid 5.
Reply
miCRoSCoPiC^eaRthLinG
Feb 12 2005, 08:53 AM
[/tab]While I'm downloading SMF, I'll try make the syntax of the JOINS a little simpler for you: [tab]Lets say we have two databases DB1 and DB2 And couple of tables in each - but what we have in common are two tables called say, tabxyz - which server different purpose but have the same name in both the databases.. [/tab]Now, if say, you have changed the active database to DB1. When you do a simple select, say SELECT * FROM tabxyz - it will fetch you the columns from DB1. What IF, you wanted to match one of the columns from the tabxyz of DB2 ?? [tab]In such a case you can: 1. Either switch over and make DB2 your active database - which is a very inconvenient process, coz then you just keep switching between the DBs to everytime you need to fetch values from the other db... OR 2. Use the explicit dbname.tablename declaration to pull values out..In this case, even while your active database is DB1, you can do a select using the following syntax: SELECT * FROM DB2.tabxyz [/tab]Now, lets consider two columns, residing in these tabxyz-s of the two databases... in DB1.tabzyx there's a column called ColA and in DB2.tabxyz, the column name is ColB. You watch to match the values of these two columns and IF they match, you write some value into yet a third column in say, DB2.tabxyz named ColC.. what you do is set up a couple of aliases to refer to ColA and ColB to make life easier for yourself. Thus: SELECT ColA from DB1.tabxyz AS ColumnA SELECT ColB from DB1.tabxyz AS ColumnBUPDATE DB2.tabxyz SET ColC='SomeValue' WHERE ( ColumnA = ColumnB ) [tab] Do you get it now ? ColumnA and ColumnB act as aliases (you can say, almost variables) pointing to ColA and ColB of the corresponding tables.. Thus, when you match the values, you avoid a lot of unnecessary headache of calling up each db and tables - instead you have two very handy aliases ready to be used... [/tab] My whole point of writing all this is - that this kind of aliasing syntax is very common in JOINS and you'll encounter them in almost any code that involves JOINS... The process of JOIN itself is what you'd make out from it's name - joining data split over multiple tables and dbs and producing the required output.. [tab] Just keep this syntax in mind and it'll help you a lot in understanding joins.. More on the actual joins later  have fun...
Reply
Ryan
Feb 14 2005, 05:51 AM
ok.. diffrent tables, same db, same prefix.
Reply
Ryan
Feb 22 2005, 09:42 PM
Thanks for your help but I am still lost, I am going to gte a php scripter to work on this and any other php scripts i will need for my site though.
Reply
vhortex
Apr 23 2005, 10:21 AM
Using Join Assume I have this database tables triwall_data batch varchar box int lot varchar and barcode2batch batch varchar barcode varchar All I want to do is get all the records from triwall_data and barcode2batch where the batches matches I will then call this: CODE select * from `qa_tracing`.`triwall_data` inner join barcode2batch on triwall_data.batch = barcode2batch.batch limit 0,10
this one is without the join CODE select * from `qa_tracing`.`triwall_data`, barcode2batch where triwall_data.batch = barcode2batch.batch limit 0,10
hope this helps... update functions almost the same.. NOTE: the sample is in assumption that you only want 10 records as is the limit code
Reply
oncombeureum
Apr 27 2005, 04:11 AM
i think the main idea is here: QUOTE $host="this_host"; $user="me"; $pass="secret_word"; $users_table="users_table_for_smf"; $member_group_col="column_name_for_member_group_in_smf"; $new_group_name="whatever"; $this_group="the_old_group"; $custom_field="custom_field_in_users_profile"; $this_value="the_value_for_custom_field";
which part is that can be modified by user ? is it QUOTE $custom_field="custom_field_in_users_profile"; $this_value="the_value_for_custom_field";
your query QUOTE $query = "UPDATE $users_table SET $member_group_col = $new_group_name "; $query .= "WHERE $member_group_col = $this_group AND "; $query .= "$custom_field = $this_value ";
$query = "UPDATE $users_table SET $member_group_col = $new_group_name "; <- doesn't need to change this part depending which table is reside in. QUOTE here is what i want this for: i need a php script to query the db, the smf users table and checks to entires in a users profile a custom field i made and the member group and if both match preset values then i want it to change the member group. i would just want this to be a php file that i can just randomly decide to goto, enter the url in firefox or any browser then it will run. what u need is an ID from smf user table that will connect to db and get the field u req. the query will look something like this. $query .= "WHERE $member_group_col = $this_group AND "; $query .= "$custom_field = $this_value "; continued. Oncom Beureum The Best Place in the City
Reply
Recent Queries:--
update join query for sql - 19.10 hr back. (1)
-
sql join script - 39.81 hr back. (1)
-
"update inner join db2" - 41.10 hr back. (1)
-
db2 update join example - 66.01 hr back. (1)
-
important questions about sql views - 89.30 hr back. (1)
-
db2 join querries - 90.13 hr back. (1)
-
sql join questions - 90.68 hr back. (1)
-
sql joins questions examples - 97.00 hr back. (1)
-
sql join questions to solve - 98.41 hr back. (1)
-
join sql questions - 114.37 hr back. (2)
-
question in joins sql - 124.10 hr back. (1)
-
sql join questions - 127.57 hr back. (1)
-
sql join question - 136.54 hr back. (1)
-
unsolved question of join in sql - 145.83 hr back. (1)
Similar Topics
Keywords : sql, join
- Warhammer Online: Age Of Reckoning
Join the WAAAGHH!! (1)
Alluraro
Come join us (1) Come join AllureRO a private ragnarok online server .Rates 20k/20k/500x Max level 999 max stat 1000
.Friendly Community .Friendly GMs .Many Customs .Events Daily Come join us i promiss you will
have a good time!! Forums - http://www.allure-ro.com/forums/index.php ? Control Panel -
http://allurero.systeminplace.net/ ....
How To Join Two Pages Togother
(3) I made i join link page and and i have a app form that i need to put into that page can anyone help
on that note....
Activision And Vivendi Join Forces
to create Activision Blizzard! (5) In a whacky and surprising move, Activision and Vivendi S.A had come together in a $18.9 billion
deal to merge Activision and Vivendi Games together to become Activision Blizzard. Both companies
have been successful with Guitar Hero, Call of Duty and the World of Warcraft series. More at
Kwokinator.com xboxrulz....
Please Help (php Join Script)
(5) Ok as you all know by now I have been working on a php based game
to help me learn php. It has been going great and it is almost done. I got some very good help on is
sues here and along with sites like php.net. However I am stuck and can not find a solution to a
problem anywere. My Problem: I want users to join but I don't want some charicters to be in
there name (example I dont want Disallowed Charicters: , ', " I would array like: CODE
$string = array( , ', "); This for some reason does not work for. CODE if(strpos($name,
$string)){ //error s....
Demonro-revolution, High Rate Quality Online Gaming Experience
We would like you to join us! (1) Dear users, I would like to invite you to come and play on a new High rate Ragnarok Online private
server. It's name is DemonRO-Revolution, and it is a high quality server, it has experienced
Support GameMasters and much more. Here is some information about the server: Are you good enough
to take part in this Revolution? DemonRO Revolution High Rate server, also known as Asylum, is a
server that fits your tastes. Asylum is a Player Kill server, and constantly updated with the
newest updates of the emulator. Asylum is very stable, and needs players to grow bigger ....
Fc Foster's: Review My Website
Visit our website and join to our team (1) Fc Foster's ....
Ideas For A Programmers' Association
JOIN!!! (19) Hi, Ev'ryone. I've got a suggestion for the ones that are quite capable af web-programming.
Let us make an organisation, an association of programmers. The aim of that association will be to
help eachother while programming. If you're in that organisation, and a problem you couldn't
solve yourself turns up, you may suddenly leave it on our forum and it will be solved together. To
join it, Leave here your suggestion. QUOTE 1. My real name. 2. My country. 3. My interests. 4.
My age. 5. Links to examples of my work. 6. what you are good at. ....
Join World Of Dungeon
(1) Very good text based game. http://world-of-dungeons.net/?link_ea_3469 ....
Free Private Sever For Ragnarok Online
Join and play for free! (4) Hey all, theres a private sever i play on.. total free, 15/15/15 sever, lvl cap 255. GM friendly.
and some new features being updated right now.. the sever is down for updates but will be back up
asap. Crimson-RO Hope you all enjoy! -Crimson-Ro Tech Support GM -Full Metal....
Blue Fusion
Hey join this game! (2) yo check this game out http://www.blfusion.com/register.php?ref=1748 ,a rpg exofusion game with
players, leaders, warriors, and followers. team work and a lone wolf.
http://www.blfusion.com/register.php?ref=1748 sign up today and become the one. /biggrin.gif'
border='0' style='vertical-align:middle' alt='biggrin.gif' /> You should also mention that that
links also gives you some points/other stuff, since it uses a reference number? I think you should
at least say that. ....
Ipbgaming.com Army System(like Kings Of Chaos)
Headed up by NilsC, please join... (0) Join the IPBGaming.com site, it is run by NilsC, and contains people from both Trap17, Astahost, and
some people I know from other sites that I beleive followed me... It is a fun game and you will love
it, try it out... Click Here For IPB Gaming ....
Funky Cool Irc Statistics With Avatars :)
If this is motivation enough to join IRC (12) HI all, For those who join us regularly on IRC and for those who don't as well - now, we have
hourly updated channel statistics being published at this address:
http://www.astahost.com/misc/ircstats/astahost.html .. For those who have no idea what channel
stats mean, just go ahead and take a look at that URL. Also as of today - those who wish to
include their avatars along with their nicks on the channel stats page, please mail me your avatars
at: microscopic.earthling@gmail.com. Due to space constraints on the page, I cannot accept avatars
larger than 80x56....
Whatpulse - Get Pulsing!
Join the astahost team! (40) WhatPulse?!?!?! For a little more community fun please join our WhatPulse team
http://whatpulse.org/stats/teams/6382/ WhatPulse is a program that counts how many keys and how
many clicks you use, it does NOT log what you type. It is a little competition and we can be at the
top! I mean come on look at our member count "2,056" with that we could go far, we could definately
get in the top 25 but we need your help. We NEED you to join our team. To get whatpulse join at
there site whatpulse.org and download there client. Its FREE! Then log into there site and join o....
Anyone Join My Chain In Age Of Mythology
newbie or export is ok (0) I have the chain in Age of Mythology it is DM_ We always play Deathmatch . If anyone is interesting
in it , give me the reply and tell me what is your name in ESO . We welcome all of people who
interesting in Deathmatch !!! Thank You Very Much ~!!....
Looking for sql, join
|
*SIMILAR VIDEOS*
Searching Video's for sql, join
|
advertisement
|
|