Jump to content
php.lv forumi

Search Php+MySql


FT3

Recommended Posts

Īsumā (meklēt visus vārdus, ja laukam ir izveidots full-text indekss)

 

$searcharray=explode(" ",substr($_GET['search'],0,50));
foreach($searcharray as $word){
    $searchstring.="+".$word."* ";
}
$searchstring=check_input($searchstring); //mysql_real_escape_string utt
$q=sprintf("SELECT * FROM tabula
           WHERE MATCH (lauks) AGAINST (%s IN BOOLEAN MODE)",
    $searchstring);
$result=mysql_query($q);

 

Tūlīt mefisto ieteiks atteikties no mysql_* :)

Link to comment
Share on other sites

un ka lai ar input ? :D jo es nesaprotu neko no funkcijam :D

$_GET['search'] ir lietotāja inputs. Viņu vispirms sadala atsevišķos vārdos, pieliek tiem priekšā "+" un beigās "*", lai meklētu visus vārdus un varētu meklēt arī nepilnus vārdus.

Tālāk parasts SELECT, tikai ar MATCH AGAINST nosacījumu.

Link to comment
Share on other sites

un ka lai ar input ? :D jo es nesaprotu neko no funkcijam :D

 

un uz 7linijas erros

 

Fatal error: Call to undefined function check_input() in C:\AppServ\www\modules\search.php on line 7

Tā nav PHP funkcija, es vienkārši caur tādu visus SQLam domātos datus izdzenu cauri.

function check_input($value){
if (!is_numeric($value)){
	$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

Link to comment
Share on other sites

itka ta ?

<form method="post" action="?go=search">
   <input type="text" name="search" />
   <input type="submit" name="search" value="OK" />
</form>

 

tavs kods !

<?php

$searcharray=explode(" ",substr($_GET['search'],0,50));
foreach($searcharray as $word){
    $searchstring.="+".$word."* ";
}
$searchstring=check_input($searchstring);
$q=sprintf("SELECT * FROM movie
           WHERE MATCH (title) AGAINST (%s IN BOOLEAN MODE)",
           $searchstring);
$result=mysql_query($q);


?>

 

 

met erroru

Fatal error: Call to undefined function check_input() in C:\AppServ\www\modules\search.php on line 7

Link to comment
Share on other sites

Uztaisi funkciju check_input() kura parbauda ievades datus, vai arii iznjem ārā to rindinju. Protams ja skriptu taisi reālai lietošanai internetā tad es ieteiktu tomēr pārbaudīt ievades datus pret injekcijām, garumu u.c.

 

Nu tad ko Tu te, pie velna, dari??! Idiots.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...