Search

45 posts by 5 authors in: Forums > CMS Builder
Last Post: May 19, 2010   (RSS)

By Jason - May 14, 2010

Hi,

First, what is that name of the field where you store the wine's name?

Second, to search a partial name for a producer, replace our $where string with this:

$where = "";

if(@$_REQUEST['title']){
$where="region='".mysql_escape($_REQUEST['title'])."' OR country='".mysql_escape($_REQUEST['title'])."' OR producer LIKE '%".mysql_escape($_REQUEST['title'])."%' OR year='".mysql_escape($_REQUEST['title'])."' OR cepage='".mysql_escape($_REQUEST['title'])."' OR wines='".mysql_escape($_REQUEST['title'])."'";
}


You can enter similar code to do a partial search on the wine's name.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search

By gcod - May 14, 2010

The name of the field in the wines table that store the wine's name is "title".

The wines table still pose problem.

The code to search the partial name for producer works, thanks.

We're getting close.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

By Jason - May 17, 2010 - edited: May 17, 2010

Hi,

We are close,

Try changing out $where variable again to this:

if(@$_REQUEST['title']){
$where="region='".mysql_escape($_REQUEST['title'])."' OR country='".mysql_escape($_REQUEST['title'])."' OR producer LIKE '%".mysql_escape($_REQUEST['title'])."%' OR year='".mysql_escape($_REQUEST['title'])."' OR cepage='".mysql_escape($_REQUEST['title'])."' OR title LIKE '%".mysql_escape($_REQUEST['title'])."%'";
}


Also, if you want to display a message if there are no records, you can use this code:

<?php if(!$winesRecords): ?>
*PUT MESSAGE HERE*
<?php endif ?>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search

By gcod - May 17, 2010

Hi Jason,

It works! I can now search for a wine name.

For the second piece of code, where should I put it exactly? I'm getting the following error:
Notice: Use of undefined constant winesRecords - assumed 'winesRecords' in /home/jeftay6/vinsbalthazard.com/produits.php on line 151

I tried to put it between the <?php foreach ($winesRecords as $record): ?> and <?php endforeach ?> and I try between <?php if($_REQUEST) : ?> and the <?php endif ?>.

Thanks.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

By Jason - May 17, 2010

Hi,

You would use it like this:

<?php if(!$winesRecords) : ?>
* Put No Records Message Here*
<?php else: ?>
<?php foreach($winesRecords as $record) : ?>
*Output Records Here*
<?php endforeach ?>
<?php endif ?>


That way you'll only go into the foreach loop if there are records in $wineRecords.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Jason - May 17, 2010

Hi,

You're just missing a dollar sign ($)

Change:
<?php if(!winesRecords): ?>
to
<?php if(!$winesRecords): ?>

That should take care of the issue.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search

By gcod - May 17, 2010

Nope it doesn't fix it.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com

By Jason - May 17, 2010

Attach your latest copy of the .php file and I'll take a look at it.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Search

By gcod - May 17, 2010

Here you go.

Thanks.
---------------------------------------------------
Webmaster, SEO Analyst, Social Media Analyst
www.gabrielcoder.com
Attachments:

produits_003.php 8K