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
mysql statement problem
Old 01-25-2007, 02:00 PM mysql statement problem
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
Ok so I ran into a problem, i have the following database schema


PHP Code:
CREATE TABLE `affiliations` (
  `
idint(11NOT NULL auto_increment,
  `
namevarchar(255NOT NULL default '',
  `
mapquesttext NOT NULL,
  `
typetext NOT NULL,
  `
visidtext NOT NULL,
  `
addresstext NOT NULL,
  `
phonevarchar(255NOT NULL default '',
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=908 ;


CREATE TABLE `affiliations_usr` (
  `
idint(11NOT NULL auto_increment,
  `
visidtext NOT NULL,
  `
visnametext NOT NULL,
  `
catvarchar(255NOT NULL default '',
  `
nametext NOT NULL,
  `
datevarchar(255NOT NULL default '0000-00-00',
  `
startvarchar(255NOT NULL default '0000-00-00',
  `
endvarchar(255NOT NULL default '0000-00-00',
  `
aff_idvarchar(255NOT NULL default '',
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1363 
affiliation is listed with all affilliations and affiliations_usr lists who is affilliated with those users. I have a script that finds all users affiliated with a certain affiliation.

I recently discovered a programming error on my part, for some reason I cannot search text with a ' in it for intance 'St. John\'s Prayer Club' because it wont find it at all... I read something about it and it said that the ' is treated like a seperate word. So after trying 100 different queries to find the name in the database I decided to use the id instead (btw if know of a way i can search with a ' then please let me know)

So i put in aff_id, but now i have 1000 entries with no aff_id, what im wondering is...

is there a way to go through all entries in affiliations_usr take the name field and compare it to affiliations (which are all in there) then take the id of that exact affilliation then go back and populate the affiliation_usr field with that id number?

Any help would be appreciated, if you dont understand something please let me know.
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
 
Register now for full access!
Old 01-26-2007, 01:43 AM Re: mysql statement problem
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
You managed to confuse me.

But, while it sounds like you have some cleaning up to do in your tables, the good news is you can definitely perform searches that include the ' character, or any other. In fact, there are a few different ways - you have choices.

Usually the best way is to create a stored procedure in the database, that takes an argument for the search text. You're probably running a PHP script (?) that creates a dynamic SQL query on the fly, embedding the text you want to find into the query. This doesn't work, as you've learned, because the search text is sent as text, and the ' character has a special meaning, besides the one it has in regular text. The database is choosing the wrong meaning to apply to it. Arguments to stored procedures are sent in binary.

You could also replace the quote mark with a wild card. Pattern searches are slower, though.

Chances are you could escape the quote mark; in SQL Server you would enclose it in two more of them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-26-2007, 04:31 AM Re: mysql statement problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You need to "escape" the single quote (') by placing a second one in front of it

use a simple replace function in whatever server side code you use. Look in the forum for the coding you use, there will be several examples.
__________________
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 offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-26-2007, 11:19 AM Re: mysql statement problem
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
Well currently in my database affiliations_usr I have this under the name cell with the slash already protecting the '

How would I go about searching for that?

Code:
St. John\'s Prayer Group
I was under the impression you could just search for this

PHP Code:
SELECT FROM `affiliations_usrwhere name 'St. John\'s Prayer Group' 
then i tried escaping it like you said and nothing, with the follwing.
PHP Code:
SELECT FROM `affiliations_usrwhere name 'St. John''s Prayer Group' 
I also tried a wildcard with the following and nothing

PHP Code:
SELECT FROM `affiliations_usrwhere name 'St. John%s Prayer Group' 
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!

Last edited by capetek; 01-26-2007 at 11:21 AM..
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
Old 01-26-2007, 11:28 AM Re: mysql statement problem
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
nvm i messed that up i replaced = with LIKE and it worked fine, thanks for the help everyone
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
Reply     « Reply to mysql statement problem
 

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.29671 seconds with 12 queries