General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 7th, 2003, 01:18 PM
GandalfTheBrown GandalfTheBrown is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 9 GandalfTheBrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Checking for things already posted.

SO, im building a "geek dictionary" for my site at www.Geekswithpcs.com . I was wondering, how would i go about making it so that when i add an entry to the dictionary (via php-mysql databse) from the form i made to add them, is it possible to check the database to make sure that the entry wasnt already added. For example. if i made a entry for teh word "Overclock" and then, a few weeks later, a staff member enters the same word, can i have it so that it will check to see if the mysql table already contains this word in a specified field?

Reply With Quote
  #2  
Old September 7th, 2003, 03:59 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
The best way to do this is to set the field containing the word (i.e. "overclock") as a UNIQUE field. See the MySQL documention for info on how to do this.

Best Regards,
Joe of 4Life
__________________
Check out 4Life today!

Reply With Quote
  #3  
Old September 11th, 2003, 06:57 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
If you set that field as unique and then someone tries to add a row that already exists will an error be returned or will mysql just not add it without reporting so?

If the latter is the case then you can query the database first -

$query = 'SELECT * FROM table WHERE field="overclock"'

If you run that query and it returns a row then its already in the database. If not then you can add the new row and know its not already there.

Hope that helps,

-KM-

Reply With Quote
  #4  
Old September 11th, 2003, 09:54 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Quote:
If you set that field as unique and then someone tries to add a row that already exists will an error be returned or will mysql just not add it without reporting so?

Suppress the query:
PHP Code:
@      $result mysql_query$this->sql$this->resource ); 

You can test the result scalar if needed
PHP Code:
if ( $result )
{
      
/* added */
}
else
{
      
/* not added - already there */

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Checking for things already posted.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway