Help with a MySQL PHP script that should identify a title

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
oskare100
Forum Commoner
Posts: 80
Joined: Sun Oct 29, 2006 5:47 am

Help with a MySQL PHP script that should identify a title

Post by oskare100 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,
I've this PHP script that should be able to identify;

Code: Select all

$mysql = mysql_connect($host, $username, $password)or die(mysql_error());
mysql_select_db($db_name, $mysql)or die(mysql_error());

$item_name= mysql_real_escape_string($item_name);
$query="SELECT
                *
        FROM
                `items`
        WHERE
                `price` = $mc_gross
                AND ('$item_name' LIKE `identify_pos` AND '$item_name' LIKE `identify_pos2`)
                AND ('$item_name' NOT LIKE `identify_neg` AND '$item_name' NOT LIKE `identify_neg2`)
        ";

$result = mysql_query($query) or die(mysql_error());
if ( false===($ident_row=mysql_fetch_assoc($result)) ) {
        // No row found
        die;
}
else {
  echo 'item_id: ', $ident_row['item_id'], "<br />\n";
}
Here is the current database structure:

Code: Select all

-- 
-- Table structure for table `items`
-- 

CREATE TABLE `items` (
  `item_id` int(11) NOT NULL auto_increment,
  `item_name` varchar(100) NOT NULL default '',
  `price` varchar(10) NOT NULL default '0',
  `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_id` int(10) NOT NULL default '0',
  `pack_id` int(10) NOT NULL default '0',
  `list_id` int(5) NOT NULL default '0',
  PRIMARY KEY  (`item_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

-- 
-- Dumping data for table `items`
-- 

INSERT INTO `items` (`item_id`, `item_name`, `price`, `identify_pos`, `identify_pos2`, `identify_neg`, `identify_neg2`, `file_id`, `pack_id`, `list_id`) VALUES 
(1, 'Package 1', '2.95', '%15GB%', '%templates%', '', '', 0, 1, 0),
(2, 'Package 2', '2.95', '', '', '%15gb%', '%templates%', 0, 2, 0);
In other words, package 1 has the words %15GB% and %templates% as positive identify words (that the title should contain to be package 1) and Package 2 has the words as negative indentify words (words that the title shouldn't contain to be package 2.

I hoped that the above structure would result in that all titles that contain 15GB and Templates are identified as Package 1 (and that works good) and that all other item titles that doesn't include the words 15GB and templates would automaticly be identified as Package 2 but that's the problem. If a title doesn't cotain 15gb or templates the script dies without any result.

I really need help with this so any info is appreciated.

Best Regards
Oskar R


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

it looks like you have them the other way around.
try this:

Code: Select all

<?php
$mysql = mysql_connect($host, $username, $password)or die(mysql_error()); 
mysql_select_db($db_name, $mysql)or die(mysql_error()); 

$item_name= mysql_real_escape_string($item_name); 
$query="SELECT * 
        FROM  `items` 
        WHERE `price` = $mc_gross 
		AND (`identify_pos` LIKE '$item_name' AND `identify_pos2` LIKE '$item_name') 
		AND (`identify_neg` NOT LIKE '$item_name' AND `identify_neg2` NOT LIKE '$item_name') 
        "; 

$result = mysql_query($query) or die(mysql_error()); 
if ( false===($ident_row=mysql_fetch_assoc($result)) ) { 
        // No row found 
        die; 
} 
else { 
  echo 'item_id: ', $ident_row['item_id'], "<br />\n"; 
} 

?>
Post Reply