Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Overwrite some values but not others
Old 01-07-2010, 12:14 PM Overwrite some values but not others
Skilled Talker

Posts: 90
Trades: 0
Currently I have
PHP Code:
$sql "REPLACE INTO $db_table(ID,URL,VALUE) VALUES ('$name','$url','$value') AND INSERT INTO $db_table('TIME') VALUES (NOW())";
if(
$result mysql_query($sql ,$db)) {} else { echo ('Sorry we are currently experiancing technical problems.'); } 
But this is not working. Bascialy I want to overwrite some of the values using REPLACE but not others using INSERT
__________________
Free Flash designs and tutorials at
Please login or register to view this content. Registration is FREE

Shorten your URL's with
Please login or register to view this content. Registration is FREE
xuroq is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-07-2010, 12:26 PM Re: Overwrite some values but not others
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You will have to run two queries. Separate them with a semicolon

REPLACE ..... WHERE .... ;
INSERT INTO ...... ;
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 12:27 PM Re: Overwrite some values but not others
Skilled Talker

Posts: 90
Trades: 0
Im not too sure what you mean. Will that not create a separate row
__________________
Free Flash designs and tutorials at
Please login or register to view this content. Registration is FREE

Shorten your URL's with
Please login or register to view this content. Registration is FREE
xuroq is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 12:34 PM Re: Overwrite some values but not others
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A semicolon indicates the end of one command any commands after that are executed independently.

so the pseudocode I posted would run the replace first followed by the insert or is that NOT your intention?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 12:40 PM Re: Overwrite some values but not others
Skilled Talker

Posts: 90
Trades: 0
No, I currently have 4 columns. ID, URL, VALUE, TIME. I want the code to update the VALUE if the ID already exists but insert the VALUE along with the ID URL and TIME if it does not exist.

Thanks, I am new to this stuff
__________________
Free Flash designs and tutorials at
Please login or register to view this content. Registration is FREE

Shorten your URL's with
Please login or register to view this content. Registration is FREE
xuroq is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 12:51 PM Re: Overwrite some values but not others
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You cannot do that in a single query, if your DB server supports stored procedures and passed parameters it would be posible to code a SP to handle the transactions.

otherwise your server side code will have to handle it

pseudocode:

SELECT id FROM table where id = [somevalue];

Code:
if id == null then
  [run insert]
else
   [run update]
end if
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 01:02 PM Re: Overwrite some values but not others
Skilled Talker

Posts: 90
Trades: 0
OK I see. What I am trying to work out is how http://whatsmytwitteraccountworth.com/ updates the 'top all time' value when a existing user is entered but does not update 'top today' or 'recent values', which I presume are calculated using the time the username is first posted posted
__________________
Free Flash designs and tutorials at
Please login or register to view this content. Registration is FREE

Shorten your URL's with
Please login or register to view this content. Registration is FREE
xuroq is offline
Reply With Quote
View Public Profile
 
Old 01-07-2010, 01:12 PM Re: Overwrite some values but not others
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,522
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It probably updates the data, then requeries the database to display the new values.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-07-2010, 01:58 PM Re: Overwrite some values but not others
Skilled Talker

Posts: 90
Trades: 0
sorted it using UPDATE
__________________
Free Flash designs and tutorials at
Please login or register to view this content. Registration is FREE

Shorten your URL's with
Please login or register to view this content. Registration is FREE
xuroq is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Overwrite some values but not others
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30888 seconds with 12 queries