Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Risolvere il problema del case sensitive.

    Salve a tutti io ho un sito di annunci e ho riscontrato un problema serio nel modulo di ricerca.

    Se cerco una parola chiave in minuscolo tipo "scarpe" i risultati saranno composti solo da annunci che hanno il titolo in minuscolo e tutti gli altri annunci che hanno il titolo "SCARPE" non vengono inclusi nei risultati.

    Io vorrei che quando un utente ricerca un prodotto, sia che lo scrivi in minuscolo, che in maiuscolo trovi realmente tutti gli oggetti attinenti alla sua richiesta e non solo quelli con titolo in minuscolo o maiuscolo.
    Qualcuno sa come fare

    Spero di essere stato chiaro nell'illustrazione.

  2. #2

  3. #3
    Ciao e grazie per la tempestiva risposta
    Di seguito trovi la query

    $query = "SELECT * FROM Annunci WHERE keywords LIKE '%".$_REQUEST['keywords']."%' AND deleted!=1 AND active=1 ";

    Puoi aiutarmi?
    Grazie

  4. #4
    Applichi l'escaping a $_REQUEST['keywords'] prima di eseguire la query?
    Il LIKE di MySQL è di default case insensitive. Sei sicuro che $_REQUEST['keywords'] non contenga dei caratteri (es. spazi, tabulazioni) che ne limitano l'efficacia nella ricerca dei record?

  5. #5
    Scusa ma non ancora molto pratico di php

    Prova a vedere se riesci a comprendere così:

    $params="?posted=1";
    foreach($_REQUEST as $key=>$value){
    $$key=$value;
    $params.=($key=="PHPSESSID")?"":"&".$key."=".$valu e; // block session id
    }
    if (!$posted) {
    $redirect=$_SERVER["PHP_SELF"].$params;
    header("Location: $redirect"); /* Redirect browser */
    return;
    }

    header5("$lang[aucsearch]");

    if ($_REQUEST['orderField']=="") $orderField = "enddate";
    else $orderField=$_REQUEST['orderField'];
    if ($_REQUEST['orderType']=="") {
    $orderType = "ASC";
    $newOrder="DESC";
    } else {
    $orderType=$_REQUEST['orderType'];
    $newOrder=($orderType=="ASC")?"DESC":"ASC";
    }

    if (isset($_REQUEST['itemsearchok'])||$_GET['advsrc']=="itemsearch") {
    $advsrc = "itemsearch";
    $query = "SELECT * FROM annunci WHERE keywords LIKE '%".$_REQUEST['keywords']."%' AND deleted!=1 AND active=1 ";
    if ($_REQUEST['category']!=0) $query .= " AND category='".$_REQUEST['category']."'";
    if ($_REQUEST['bnonly']=="yes") $query .= " AND bn='Y'";
    if ($_REQUEST['rponly']=="yes") $query .= " AND rp='Y'";
    if ($_REQUEST['dutchonly']=="yes") $query .= " AND auctiontype='dutch'";
    if ($_REQUEST['results']==2) $query .= " AND closed=0";
    if ($_REQUEST['results']==3) $query .= " AND closed=1";
    if ($_REQUEST['country']!="all") $query .= " AND country='".$_REQUEST['country']."'";
    if ($_REQUEST['listin']=="auction") $query .= " AND listin!='store'";
    else if ($_REQUEST['listin']=="store") $query .= " AND listin!='auction'";

    if (trim($_REQUEST['zip'])!="") $query .= " AND zip LIKE '%".$_REQUEST['zip']."%'";
    if (!$_REQUEST['orderField']) {
    if ($_REQUEST['sortby']==1) {
    $orderField = "enddate";
    $orderType = "ASC";
    }
    if ($_REQUEST['sortby']==2) {
    $orderField = "startdate";
    $orderType = "DESC";
    }
    if ($_REQUEST['sortby']==3) {
    $orderField = "bidstart";
    $orderType = "ASC";
    }
    }
    } else if (isset($_REQUEST['usersearchok'])||$_GET['advsrc']=="usersearch") {
    $advsrc = "usersearch";
    $query = "SELECT DISTINCT auct.id, auct.picpath, auct.itemname, auct.maxbid, auct.nrbids, auct.currency, auct.enddate,
    auct.bidstart, auct.bn, auct.bnvalue, auct.zoom, auct.accept_payment_systems FROM
    users AS users, annunci AS auct WHERE
    (users.username LIKE '%".$_REQUEST['keywords']."%')
    AND users.id=auct.ownerid AND auct.deleted!=1 AND auct.active=1";

    if ($_REQUEST['results']==2) $query .= " AND auct.closed=0";
    if ($_REQUEST['results']==3) $query .= " AND auct.closed=1";

    if (!$_REQUEST['orderField']) {
    if ($_REQUEST['sortby']==1) {
    $orderField = "auct.enddate";
    $orderType = "ASC";
    }
    if ($_REQUEST['sortby']==2) {
    $orderField = "auct.startdate";
    $orderType = "DESC";
    }
    if ($_REQUEST['sortby']==3) {
    $orderField = "auct.bidstart";
    $orderType = "ASC";
    }
    }
    } else if (isset($_REQUEST['buyersearchok'])||$_GET['advsrc']=="buyersearch") {
    $advsrc = "buyersearch";
    $query = "SELECT DISTINCT auct.id, auct.picpath, auct.itemname, auct.maxbid, auct.nrbids, auct.currency, auct.enddate,
    start, auct.bn, auct.bnvalue, auct.zoom, auct.accept_payment_systems FROM
    users AS users, annuncio AS auct, bids AS bid WHERE
    (users.username LIKE '%".$_REQUEST['username']."%')
    AND users.id=bid.bidderid AND auct.id=bid.auctionid AND auct.deleted!=1 AND auct.closed=0 AND auct.active=1 ";
    } else {
    $query = "SELECT * FROM annunci
    WHERE (lcase(keywords) LIKE lcase('%".$_REQUEST['basicsearch']."%') OR ucase(keywords) LIKE ucase('%".$_REQUEST['basicsearch']."%')) AND active=1 AND closed=0 AND deleted!=1";
    }

    $additionalVars = "&basicsearch=".$_REQUEST['basicsearch']."&advsrc=".$advsrc.
    "&results=".$_REQUEST['results']."&sortby=".$_REQUEST['sortby'].
    "&keywords=".$_REQUEST['keywords']."&country=".$_REQUEST['country'].
    "&bnonly=".$_REQUEST['bnonly']."&rponly=".$_REQUEST['rponly']."&dutchonly=".$_REQUEST['dutchonly']."&username=".$_REQUEST['username']."&listin=".$_REQUEST['listin'];
    if ($_GET['start'] == "") $start = 0;
    else $start = $_GET['start'];
    $limit = 20;

    $totalResults = getSqlNumber($query." ORDER BY ".$orderField." ".$orderType."");
    $resultsQuery = mysql_query($query." ORDER BY ".$orderField." ".$orderType." LIMIT ".$start.",".$limit."");
    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.