Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:51:08+00:00 2026-06-02T00:51:08+00:00

I’m converting a classified ad/flat file perl script to use mysql/dbi; I have this

  • 0

I’m converting a classified ad/flat file perl script to use mysql/dbi;
I have this search code and it’s not working very well. It will find Vintage_Trailers from item_category but if I include item_state it won’t find anything. I need it to find only Vintage_Trailers only in Nevada for instance. But the user may not choose a state so only Vintage_trailers should be found. Or maybe only keywords ‘Shasta’…Something ‘out of the box’ that I can modify would be excellent. Any help is appreciated.

$searchfor="$multi_input $keywords $user $item_category $item_city $item_state";
my $dsn = "DBI:mysql:$database";
my $dbh = DBI->connect($dsn, $userid, $password ) 
          or die $DBI::errstr;
my @searchthings = split(/ /,$searchfor);
foreach $thing(@searchthings)
     {
    if ($thing){
        $statement .= "(item_name like '%$thing%' or 
        item_desc like '%$thing%' or 
        item_desc2 like '%$thing%' or 
        item_category like '%$thing%' or 
        item_city like '%$thing%' or 
        item_state like '%$thing%' or 
        user like '%$thing%' ) ";
    }
}

$sth = $dbh->prepare(qq(select * from ads where $statement)) or  die $DBI::errstr;
$sth->execute();
    while ((my (@rows)) = $sth->fetchrow_array)
    {
    $total_row_count= $sth->rows;
    $database_rows = join ("\|", @rows);
    push (@database_rows,$database_rows);
    }
$sth->finish() or  die $DBI::errstr;
 $dbh->disconnect() or  die $DBI::errstr;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:51:10+00:00Added an answer on June 2, 2026 at 12:51 am
    $ANDOR = param('andor');#creates an AND OR search
    if($ANDOR eq ""){ $ANDOR="AND";}
    
    if($item_category){
    $item_category = "$item_category";
    } else{  $item_category=" "; 
    }
    $statement .= "item_category LIKE  ? ";
    push(@binds,$item_category);
    
    
    if($item_state){
    $statement .= " $ANDOR item_state LIKE ? ";
    push(@binds,$item_state);
    }
    if($item_city){
    $statement .= " $ANDOR item_city LIKE ? ";
    push(@binds,$item_city);
    }
    if($db_id){
    $statement .= " $ANDOR db_id = ? ";
    push(@binds,$db_id);
    }
    
    $keywords=param('keywords');
    if(param('as_a_phrase')){
    $keywords =~ s/ /\+/g;
    }
    if($keywords)
    {
    if(param('searchmatch') eq "exact")
    {
    $statement .= " $ANDOR (item_name = ? OR item_desc = ? OR item_desc2 = ? )";#
    push(@binds,$keywords,$keywords,$keywords);
    
    }
    else
    {   $statement .= " $ANDOR  ";
    
    my @keywords = split(/ /,$keywords);
    my $keywordcount=@keywords;
    
    foreach my $keyword(@keywords)
    { $keywordcount2++;
    $statement .= " (item_name LIKE ? 
    OR item_desc LIKE ? 
    OR item_desc2 LIKE ? )";
    if ($keywordcount2 == $keywordcount) {$statement .= "";} else{ $statement .= " OR "; }
    push(@binds, "%$keyword%","%$keyword%","%$keyword%");
    }
    }
    }
    
    $date_begin=param('date_begin');
    if($date_begin){
    $statement .= " $ANDOR modification_time > ? "; 
    push(@binds,$date_begin);
    }
    
    if($user){
    $statement .= " $ANDOR user LIKE ? ";
    push(@binds,$user);
    }
    
    
    $price_low=param('price_low');
    $price_high=param('price_high');
    if (($price_low) && ($price_high)){
    $statement .= " $ANDOR item_price BETWEEN ? AND ? ";
    push(@binds,$price_low,$price_high);
    }
    elsif (($price_low) && ($price_high eq "")){
    $statement .= " $ANDOR item_price > ? ";
    push(@binds,$price_low);
    }
    elsif (($price_high) && ($price_low eq "")){
    $statement .= " $ANDOR item_price BETWEEN ? AND ? ";
    push(@binds,1,$price_high);
    }
    else
    {  }
    
    
    my $sth = $dbh->prepare(qq(SELECT * FROM ads WHERE $statement )) or  die $DBI::errstr;
    $sth->execute(@binds);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.