![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
a sql question anyone?
I wonder how many of you know SQL.
$sql=" UPDATE records set appear_order='3' WHERE id='19' ; UPDATE records set appear_order='5' WHERE id='16' ; UPDATE records set appear_order='4' WHERE id='17' ; UPDATE records set appear_order='6' WHERE id='20' ; UPDATE records set appear_order='2' WHERE id='18' ; "; is there a better shorter way to do this query? can all these updated even be done at once? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Feb 2003
Posts: 1,020
|
I think the way you've got it there is probably the best you're going to get. You may be able to optimize code around that in the program, but I don't think you can really get any tighter than that with the sql query itself, since all the values and records are different.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Jan 2005
Posts: 422
|
Good question... but I don't think there's a quick way since they are different rows in the table. Haven't seen any sql looping commands...
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
If you have different where clauses, that's the way you have to do it.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
i thought i'd ask before I update 8747 rows
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
8748 that is (just made another sale while posting)
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
hmm, there might be a way. Are you changing appear_order from one var to another var? Like all 1's to 5's or something similair?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Nov 2002
Location: Valencia, CA
Posts: 2,906
|
on an update, if you are updating every single record just leave out the WHERE statement
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Jun 2003
Location: United States
Posts: 2,918
|
I think what you're trying to do is called "Batch Updates".
__________________
icq: 320340263 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
Confirmed User
Join Date: Nov 2002
Location: Valencia, CA
Posts: 2,906
|
Quote:
Disregard. I just quick glanced at it and realized just now that there are unique values to that column. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Join Date: May 2003
Posts: 183
|
if you are just updating the appear_id's and nothing else you can do something like this.
UPDATE records set appear_order=appear_order + 1; that assumes you want to auto_increment the number by 1 in EVERY ROW in the DB; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
Quote:
nope, still need to specify ID |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Posts: 5,344
|
wait, the SQL query does'nt work. i get:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE records set appear_order='2' WHERE id='19'; UPDATE recor so it can't do more then 1 action in a query?? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Confirmed User
Join Date: May 2003
Posts: 183
|
nope. you will have to do a loop through each of the id's you wan't to update.
my $sql = "update appear_count='?' where ID='?'"; my $sth = $dbh->prepare($sql); foreach my $ID (@ids){ $sth->execute(APPEAR_COUNT, $ID); } |
![]() |
![]() ![]() ![]() ![]() ![]() |