![]() |
|
#1
|
|||
|
|||
Verify if a specific data exists in a tableHello,
I know how to write some elementary php scripts to interact with a mysql database. But I am confusing myself right now on how to create this script. I have a database that will include specific location information on each webcam that is on my site. (lat/lon, weather codes, UTC, etc.) Here is the table info: (extra info deleted) CREATE TABLE `weather` ( `country` char(25) NOT NULL, `state` char(25) NOT NULL, `city` char(25) NOT NULL, ) ENGINE=MyISAM ; I want to check this table to see if the information exists already or not, and if it does not exist, then add the data. I can have multiple webcams that have the same 'United States', 'Alaska', 'Juneau' , but this table will only have one entry per 'United States', 'Alaska', 'Juneau'. I have read that you should be able to query the table and get a true/ false response as to whether this location exist already. But so far my attempts are falling short. PHP Code:
Thanks, Richard http://www.thewebcamsite.net |
|||
|
#2
|
||||
|
||||
Re: Verify if a specific data exists in a tableI think you could get away with using:
Code:
But for this to work, you need to set at least a primary key or a unique key i.e. a key comprising all three columns. Also, you might want to redesign your MySQL table. For one, it's not normalised in the first form i.e. so many repeated data in columns like `country`, and `state`, not to mention the likelyhood that the data will be tainted with typos e.g. US, USA, United States, U. States, etc. |
|
#3
|
|||
|
|||
Re: Verify if a specific data exists in a tableHow would you make a primary key comprising those three columns??
Also, you stated normilized ?? Quote:
What should I be doing?? Thanks, Richard |
|
#4
|
||||
|
||||
Re: Verify if a specific data exists in a tableWell, I would probably create at least 3 MySQL DB tables that look like this:
Code:
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Asynchronous transfer question | crystalattice | Miscellaneous Programming Forum | 2 | 24-Jan-2007 21:39 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 14:12 |
| Strange C++ code memory leakage problem | gaoanyu | C++ Forum | 7 | 04-Nov-2005 09:09 |
| Help extracting specific data from text file | wariner | C++ Forum | 4 | 24-Apr-2005 04:14 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The