Jump to content

[SOLVED] SELECT not pulling all relevant records


arkweb

Recommended Posts

I have a db of recipes and my SELECT statement is giving me fits.

SELECT * FROM modx_recipes WHERE published = '1' AND (category LIKE '%$search%' OR category = '$search' OR title LIKE '%$search%' OR  title = '$search' OR intro LIKE '%$search%' OR ingredients LIKE '%$search%' OR instructions LIKE '%$search%' ) ORDER BY title ASC

 

I have a dropdown menu to select categories. That works fine. And then I have an input box for typing search terms. A specific example would be, say, hummus recipes. If I type in 'hummus', it will return 'Edamame Hummus'. If I type in 'hum', it will return all of the hummus recipes. But, and here's where it gets weird to me, if I type in 'Easy Hummus', which is the exact title of one of the recipes, it returns absolutely nothing. Even when I simplify my statement to

 

SELECT * FROM modx_recipes WHERE title = 'Easy Hummus'

or even

SELECT * FROM modx_recipes WHERE id = '197'

 

My mysql knowledge is not extensive, so I'm sure I'm missing something incredibly obvious. Any help would be greatly appreciated.

 

PHP 4.3.9

MySQL 4.1.20

 

CREATE TABLE `modx_recipes` (\n  `id` int(4) NOT NULL auto_increment,\n  `category` varchar(255) NOT NULL default '',\n  `title` varchar(255) NOT NULL default '',\n  `author` varchar(255) NOT NULL default '',\n  `intro` text NOT NULL,\n  `date` varchar(20) NOT NULL default '',\n  `published` char(1) NOT NULL default '',\n  `vegetarian` char(1) NOT NULL default '',\n  `servings` varchar(20) NOT NULL default '',\n  `ingredients` text NOT NULL,\n  `instructions` text NOT NULL,\n  `image` varchar(100) NOT NULL default '',\n  `notes` text NOT NULL,\n  `keywords` text NOT NULL,\n  `featured` char(1) NOT NULL default '',\n  `homepage_featured` char(1) default NULL,\n  PRIMARY KEY  (`id`),\n  KEY `index_title` (`title`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8

 

 

 

 

Link to comment
Share on other sites

I figured it out. It was an error in my php. I had

if($row = mysql_fetch_array($result))
{
print '<table class="article_list">';
print '<tr><th>Title</th><th>Rating</tr>';
}
while($row = mysql_fetch_array($result))
{
$rating_id =  'r' . $row['id'];
$row_color = ($row_count % 2) ? $color1 : $color2; 

print '<tr bgcolor="'.$row_color.'"><td class="title"><a href="/index.php?id=1648&recipe='.$row['id'].'&name='.$row['title'].'">'.$row['title'].'</a></td><td></td></tr>';
$row_count ++;
}
print '</table>';

 

Apparently, the

if($row = mysql_fetch_array($result))
{
print '<table class="article_list">';
print '<tr><th>Title</th><th>Rating</tr>';
}

 

Was screwing it up.

 

Thanks for all of your replies.

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.