Current location: Hot Scripts Forums » Programming Languages » PHP » Check rows in a table (see if $title contains X but not X) and find a matching row...


Check rows in a table (see if $title contains X but not X) and find a matching row...

Reply
  #1 (permalink)  
Old 01-03-07, 09:51 AM
Oskare100 Oskare100 is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Check rows in a table (see if $title contains X but not X) and find a matching row...

Hello,
I have a table where I add the items I have. When I receive a new order I get the title of the item the new order contains, and I assign that title the variable $title in the script that is supposed to match/identify the new order with an item in my database.

Here is the database structure;
Code:
CREATE TABLE `items` (
  `item_id` int(11) NOT NULL auto_increment,
  `item_name` varchar(100) NOT NULL default '',
  `price` varchar(30) NOT NULL default '',
  `identify_pos` varchar(50) NOT NULL default '',
  `identify_pos2` varchar(50) NOT NULL default '',
  `identify_neg` varchar(50) NOT NULL default '',
  `identify_neg2` varchar(50) NOT NULL default '',
  `file_name` varchar(100) NOT NULL default '',
  `file_pack` varchar(30) NOT NULL default '',
  PRIMARY KEY  (`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
So I need the script to see if the title matches any of the items in my database. As soon as the script finds a row where the $title contains identify_pos and identify_pos2 but not identify_neg or identify_neg2 then it should get the item_id of that item and continue. If it can't find any match, then do something else..

Also, identify_pos, identify_pos2, identify_neg and identify_neg2 can be empty but I hope that doesn't make it more difficult.. If it does it is OK if all must contain something.

Maybe I've forgotten to mention something important here but I'mm monitor this thread so just reply.. Is it possible to do that with PHP and if, how can I do it? I'm not that good at PHP so I can't figure out how to do that myself..

Thanks in advance,
/Oskar R
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-03-07, 05:00 PM
odi's Avatar
odi odi is offline
Newbie Coder
 
Join Date: Oct 2006
Location: Switzerland
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
I guess you can figure out how to run a sql-query with php.

What you need is something like the following:

Code:
select 
	item_id
from
	items
where
	identify_pos  = '$title' and 
	identify_pos2 = '$title' and
	(identify_neg != '$title' or 
	identify_neg2 != '$title');
Note:$title refers to the PHP variable and has nothing to do with SQL

And now you must handle if you get any return value (continue script as you wrote) and when you get nothing (do something else according to you).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 11:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.