Jump to content

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


oskare100

Recommended Posts

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 ;
[/CODE]

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
Link to comment
Share on other sites

Does the title have to be in both (identify_pos, identify_pos2) or can it be in in just one of those. If it need to be in both, then...

[code]SELECT item_id FROM items WHERE identify_pos = '" . $title . "' AND identify_pos2 = '" . $title . "'[/code]

OR, if it can be in one or the other

[code]SELECT item_id FROM items WHERE identify_pos = '" . $title . "' OR identify_pos2 = '" . $title . "'[/code]


In other words..., the query can be done any way you want, but how it's done will be based on exactly how you want the restriction to work. But then again, if you already have a order, then why don't you have them [b]item_id[/b] with the order, seeing it is the [b]key[/b] to the items table!

printf

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.