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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 02-07-2005, 01:42 PM   #1
Zester
Confirmed User
 
Zester's Avatar
 
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?
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:46 PM   #2
Fuckin Bill
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.
Fuckin Bill is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:47 PM   #3
MGPspots
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...
MGPspots is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:49 PM   #4
swedguy
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.
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:51 PM   #5
Zester
Confirmed User
 
Zester's Avatar
 
Industry Role:
Join Date: Jul 2003
Posts: 5,344
i thought i'd ask before I update 8747 rows
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:51 PM   #6
Zester
Confirmed User
 
Zester's Avatar
 
Industry Role:
Join Date: Jul 2003
Posts: 5,344
8748 that is (just made another sale while posting)
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:54 PM   #7
swedguy
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?
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:57 PM   #8
Warden
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
__________________
AIM: ZeeRiddler
ICQ: 128160005
Warden's MS
Warden is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 01:59 PM   #9
swedguy
Confirmed User
 
Industry Role:
Join Date: Jan 2002
Posts: 7,981
Quote:
Originally Posted by Warden
on an update, if you are updating every single record just leave out the WHERE statement
appear_order is different in his example, so that will not work. But what you're saying might work if for example all 1's are changed to 5's, 2 to 9 and so on.
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:01 PM   #10
beergood
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
beergood is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:01 PM   #11
Warden
Confirmed User
 
Join Date: Nov 2002
Location: Valencia, CA
Posts: 2,906
Quote:
Originally Posted by swedguy
appear_order is different in his example, so that will not work. But what you're saying might work if for example all 1's are changed to 5's, 2 to 9 and so on.

Disregard. I just quick glanced at it and realized just now that there are unique values to that column.
__________________
AIM: ZeeRiddler
ICQ: 128160005
Warden's MS
Warden is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:14 PM   #12
Zester
Confirmed User
 
Zester's Avatar
 
Industry Role:
Join Date: Jul 2003
Posts: 5,344
Quote:
Originally Posted by Warden
Disregard. I just quick glanced at it and realized just now that there are unique values to that column.
yes , different values BUT the appear_id's are increasing values by 1 each time
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:21 PM   #13
RefaStud
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;
RefaStud is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:23 PM   #14
Zester
Confirmed User
 
Zester's Avatar
 
Industry Role:
Join Date: Jul 2003
Posts: 5,344
Quote:
Originally Posted by RefaStud
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;

nope, still need to specify ID
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 02:26 PM   #15
Zester
Confirmed User
 
Zester's Avatar
 
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??
__________________
* Mainstream ? $65 per sale
* new male contraception
Zester is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 02-07-2005, 03:40 PM   #16
RefaStud
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);
}

Last edited by RefaStud; 02-07-2005 at 03:42 PM.. Reason: didn't finish.. UGH
RefaStud is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.