<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ricerca semplice su mysql]]></title><description><![CDATA[<p dir="auto">ciao a tutti<br />
premesso che sono neofita di php...<br />
ho trovato uno script di ricerca semplice l'ho settato ma restituisce questo errore</p>
<p dir="auto"><strong>Warning</strong>: mysql_num_rows(): supplied argument is not a valid MySQL result resource in <strong>c:\programmi\easyphp\www\search1.php</strong> on line <strong>37</strong><br />
Couldn't execute query</p>
<pre><code class="language-html">&lt;?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 =  "&lt;p&gt;Search Error&lt;/p&gt;&lt;p&gt;Please enter a search...&lt;/p&gt;" ;
  }
// check for a search parameter
if (!isset($var)){
  $resultmsg =  "&lt;p&gt;Search Error&lt;/p&gt;&lt;p&gt;We don't seem to have a search parameter! &lt;/p&gt;" ;
  }
// 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 &amp;&amp; $row_set_num == 0){
   $resultmsg = "&lt;p&gt;Search results for: ". $trimmed."&lt;/p&gt;&lt;p&gt;Sorry, your search returned zero results&lt;/p&gt;" ;
}
   //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
?&gt;
&lt;form action="search1.php" method="get" name="search"&gt;
  &lt;div align="center"&gt;
      &lt;input name="q" type="text" value=" &lt;?php echo $q; ?&gt; " size="15"&gt; 
      &lt;input name="search" type="submit" value="Search"&gt;
  &lt;/div&gt;
&lt;/form&gt;
&lt;?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" , "&lt;b&gt; //1&lt;/b&gt;" , $row_linkcat[ 'field1' ] );
  $linkhigh = preg_replace ( "'($var)'si" , "&lt;b&gt; //1&lt;/b&gt;" , $row_linkcat[ 'field2' ] );
  $linkdesc = preg_replace ( "'($var)'si" , "&lt;b&gt; //1&lt;/b&gt;" , $row_linkcat[ 'field3' ] );
foreach($trimmed_array as $trimm){
    if($trimm != 'b' ){
        $titlehigh = preg_replace( "'($trimm)'si" ,  "&lt;b&gt; //1&lt;/b&gt;" , $titlehigh);
        $linkhigh = preg_replace( "'($trimm)'si" , "&lt;b&gt; //1&lt;/b&gt;" , $linkhigh);
        $linkdesc = preg_replace( "'($trimm)'si" ,  "&lt;b&gt; //1&lt;/b&gt;" , $linkdesc); 
     }
//end foreach $trimmed_array
?&gt;
 &lt;p&gt;
&lt;?php echo $titlehigh; ?&gt;&lt;br&gt;
&lt;?php echo $linkhigh; ?&gt;&lt;br&gt;
&lt;?php echo $linkhigh; ?&gt;
&lt;/p&gt;
 
&lt;?php 
}    
   if($row_num_links_main &gt; $limit){
   // next we need to do the links to other search result pages
      if ($s&gt;=1) { // do not display previous link if 's' is '0'
        $prevs=($s-$limit);
         echo "&lt;div align='left'&gt;&lt;a href='$PHP_SELF?s=$prevs&amp;q=$var&amp;catid=$catid'&gt;Previous " .$limit. "&lt;/a&gt;&lt;/div&gt;";
      }
 
     // check to see if last page
     $slimit =$s+$limit;
       if (!($slimit &gt;= $row_num_links_main) &amp;&amp; $row_num_links_main!=1) {
     // not last page so display next link
          $n=$s+$limit;
           echo "&lt;div align='right'&gt;&lt;a href='$PHP_SELF?s=$n&amp;q=$var&amp;catid=$catid'&gt;Next " .$limit. "&lt;/a&gt;&lt;/div&gt;";
        }
    }
}  //end foreach $newarr
?&gt;
</code></pre>
<p dir="auto">dove la riga 37 è: $row_num_links_main = mysql_num_rows ($numresults);</p>
<p dir="auto">qualcuno può aiutarmi?</p>
<p dir="auto">grazie</p>
]]></description><link>https://dev.connect.gt/topic/27997/ricerca-semplice-su-mysql</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Dec 2026 06:28:37 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/27997.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Feb 2007 15:58:35 GMT</pubDate><ttl>60</ttl></channel></rss>