Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. ricerca semplice su mysql

ricerca semplice su mysql

Pianificato Fissato Bloccato Spostato Coding
1 Post 1 Autori 1.4k Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • L
    L
    linno
    scritto su ultima modifica di
    User Attivo 0
    #1
    ricerca semplice su mysql

    ciao a tutti
    premesso che sono neofita di php...
    ho trovato uno script di ricerca semplice l'ho settato ma restituisce questo errore

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\programmi\easyphp\www\search1.php on line 37
    Couldn't execute query

    <?php 
    $hostname_logon = "localhost" ;   
    $database_logon = "testmp" ;  
    $username_logon = "" ;  
    $password_logon = "" ;   
    //open database connection
     $connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );
     //select database
     mysql_select_db($database_logon) or die ( "Unable to select database!" );
    //specify how many results to display per page
    $limit = 10;
    // Get the search variable from URL
      $var = @$_GET['q'] ;
    //trim whitespace from the stored variable
      $trimmed = trim($var);  
    //separate key-phrases into keywords
      $trimmed_array = explode(" ",$trimmed); 
    // check for an empty string and display a message.
    if ($trimmed == "") {
      $resultmsg =  "<p>Search Error</p><p>Please enter a search...</p>" ;
      }
    // check for a search parameter
    if (!isset($var)){
      $resultmsg =  "<p>Search Error</p><p>We don't seem to have a search parameter! </p>" ;
      }
    // Build SQL Query for each keyword entered 
    foreach ($trimmed_array as $trimm){
          // EDIT HERE and specify your table and field names for the SQL query
         $query = "SELECT * FROM sedi_aziendali WHERE indirizzo LIKE '%$trimm%' OR field2 like '%$trimm%' OR field3 like '%$trimm%' ORDER BY indirizzo  DESC" ; 
         // Execute the query to  get number of rows that contain search kewords
         $numresults= mysql_query ($query);
         $row_num_links_main = mysql_num_rows ($numresults);
         // next determine if 's' has been passed to script, if not use 0.
         // 's' is a variable that gets set as we navigate the search result pages.
         if (empty($s)) {
             $s=0;
         }
          // now let's get results.
          $query .= " LIMIT $s,$limit" ;
          $numresults = mysql_query ($query) or die ( "Couldn't execute query" );
          $row= mysql_fetch_array ($numresults);
          //store record id of every item that contains the keyword in the array we need to do this to avoid display of duplicate search result.
          do{
              $adid_array[] = $row[ 'fieldid' ];
          }while( $row= mysql_fetch_array($numresults));
     } //end foreach
    if($row_num_links_main == 0 && $row_set_num == 0){
       $resultmsg = "<p>Search results for: ". $trimmed."</p><p>Sorry, your search returned zero results</p>" ;
    }
       //delete duplicate record id's from the array. To do this we will use array_unique function
       $tmparr = array_unique($adid_array); 
       $i=0; 
       foreach ($tmparr as $v) { 
           $newarr[$i] = $v; 
           $i++; 
       } 
    // now you can display the results returned. But first we will display the search form on the top of the page
    ?>
    <form action="search1.php" method="get" name="search">
      <div align="center">
          <input name="q" type="text" value=" <?php echo $q; ?> " size="15"> 
          <input name="search" type="submit" value="Search">
      </div>
    </form>
    <?php
    // display what the person searched for.
     if( isset ($resultmsg)){
      echo $resultmsg;
      exit();
     }else{
      echo "Search results for: " . $var;
     }
     
    foreach($newarr as $value){
     // EDIT HERE and specify your table and field names for the SQL query
    $query_value = "SELECT * FROM sedi_aziendali WHERE indirizzo = '$value'";
     $num_value=mysql_query ($query_value);
     $row_linkcat= mysql_fetch_array ($num_value);
     $row_num_links= mysql_num_rows ($num_value);
    //now let's make the keywods bold. To do that we will use preg_replace function. 
    //Replace field
      $titlehigh = preg_replace ( "'($var)'si" , "<b> //1</b>" , $row_linkcat[ 'field1' ] );
      $linkhigh = preg_replace ( "'($var)'si" , "<b> //1</b>" , $row_linkcat[ 'field2' ] );
      $linkdesc = preg_replace ( "'($var)'si" , "<b> //1</b>" , $row_linkcat[ 'field3' ] );
    foreach($trimmed_array as $trimm){
        if($trimm != 'b' ){
            $titlehigh = preg_replace( "'($trimm)'si" ,  "<b> //1</b>" , $titlehigh);
            $linkhigh = preg_replace( "'($trimm)'si" , "<b> //1</b>" , $linkhigh);
            $linkdesc = preg_replace( "'($trimm)'si" ,  "<b> //1</b>" , $linkdesc); 
         }
    //end foreach $trimmed_array
    ?>
     <p>
    <?php echo $titlehigh; ?><br>
    <?php echo $linkhigh; ?><br>
    <?php echo $linkhigh; ?>
    </p>
     
    <?php 
    }    
       if($row_num_links_main > $limit){
       // next we need to do the links to other search result pages
          if ($s>=1) { // do not display previous link if 's' is '0'
            $prevs=($s-$limit);
             echo "<div align='left'><a href='$PHP_SELF?s=$prevs&q=$var&catid=$catid'>Previous " .$limit. "</a></div>";
          }
     
         // check to see if last page
         $slimit =$s+$limit;
           if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
         // not last page so display next link
              $n=$s+$limit;
               echo "<div align='right'><a href='$PHP_SELF?s=$n&q=$var&catid=$catid'>Next " .$limit. "</a></div>";
            }
        }
    }  //end foreach $newarr
    ?>
    

    dove la riga 37 è: $row_num_links_main = mysql_num_rows ($numresults);

    qualcuno può aiutarmi?

    grazie

    1 Risposta Ultima Risposta
    Miglior risposta 0
    0

    Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.

    Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.

    Con il tuo contributo, questo post potrebbe essere ancora migliore 💗

    Registrati Accedi
    Rispondi
    • Risposta alla discussione
    Effettua l'accesso per rispondere
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti


    • Accedi

    • Non hai un account? Registrati

    • Accedi o registrati per effettuare la ricerca.
    • Primo post
      Ultimo post
    Home Accedi Registrati
    Menu
    • CATEGORIES
    • La Community Connect.gt
    • Presentati alla Community
    • News Ufficiali da Connect.gt
    • Internet News
    • A Scuola Di
    • Digital Marketing
    • Intelligenza Artificiale
    • SEO & GEO
    • Web Marketing e Content
    • Google Analytics e Web Analytics
    • Google Ads & Advertising
    • YouTube
    • TikTok, Instagram e altri Social
    • Google Adsense, Affiliazioni e Guadagno
    • E-Commerce
    • Coding e Sistemistica
    • Help Center: consigli per il tuo progetto
    • Hosting e Cloud
    • Coding
    • CMS & Piattaforme Self-Hosted
    • Annunci e Collaborazioni
    • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
    • Collaborazioni WEB e Lavoro: offro e cerco
    • Impresa, Fisco e Leggi
    • Consulenza Legale e Professioni Web
    • Consulenza Fiscale, Imprese, Startup e P.Iva
    • Gli Off Topic
    • PC, Smartphone e altri Hardware
    • Tutti i Software
    • GT Fetish Cafè
    • Discussioni
    • Non letti 0
    • Recenti
    • Hashtag
    • Popolare
    • Utenti
    • Privacy
    • Termini e condizioni
    • © 2026 Search On Media Group S.r.l.