MySQL Free-text zoeken in meerdere tabellen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
//error_reporting(E_ALL);
if(!$_GET['c']) {
?>
<form action='advs.php?c=1' method=POST>
<b>Find Results with: </b><br>
Any of these words: <input type='text' length=40 name='any'> <br>
All of these words: <input type='text' length=40 name='all'> <br>
None of these words: <input type='text' length=40 name='none'> <br>
<input type='submit' value='Search'>
</form>
<?php
} elseif($_GET['c']) {
include_once 'config.php';
include_once 'functions.php';
connectdb();
$all = $_POST['all'];
$any = $_POST['any'];
$none = $_POST['none'];
if((!$all) || ($all == '')) { $all = ''; } else { $all = '+(' . $all . ')'; }
if((!$any) || ($any == '')) { $any = ''; }
if((!$none) || ($none == '')) { $none = ''; } else { $none = '-(' . $none . ')'; }
$query = "SELECT *,
MATCH(body) AGAINST ('" . $all . $none . $any . "' IN BOOLEAN MODE) AS score
FROM db6
WHERE MATCH(body) AGAINST ('" . $all . $none . $any . "' IN BOOLEAN MODE)";
$artm1 = MySQL_query($query);
if(!$artm1) {
echo MySQL_error().'<br>' . $query . '<br>';
}
echo '<b>Matches</b><br>';
if(MySQL_num_rows($artm1) > 0) {
echo '<table>';
echo '<tr><td>Score </td><td>Title </td><td>Body</td></tr>';
while($artm2 = MySQL_fetch_array($artm1)) {
$val = round($artm2['score'], 3);
$val = ($val*100);
echo '<tr><td>' . $val . '</td>';
echo '<td>' . $artm2['poster'] . '</td>';
echo '<td>' . $artm2['body'] . '</td></tr>';
}
echo '</table>';
} else {
echo 'No Results were found in this category.<br>';
}
echo '<br>';
}
?>
//error_reporting(E_ALL);
if(!$_GET['c']) {
?>
<form action='advs.php?c=1' method=POST>
<b>Find Results with: </b><br>
Any of these words: <input type='text' length=40 name='any'> <br>
All of these words: <input type='text' length=40 name='all'> <br>
None of these words: <input type='text' length=40 name='none'> <br>
<input type='submit' value='Search'>
</form>
<?php
} elseif($_GET['c']) {
include_once 'config.php';
include_once 'functions.php';
connectdb();
$all = $_POST['all'];
$any = $_POST['any'];
$none = $_POST['none'];
if((!$all) || ($all == '')) { $all = ''; } else { $all = '+(' . $all . ')'; }
if((!$any) || ($any == '')) { $any = ''; }
if((!$none) || ($none == '')) { $none = ''; } else { $none = '-(' . $none . ')'; }
$query = "SELECT *,
MATCH(body) AGAINST ('" . $all . $none . $any . "' IN BOOLEAN MODE) AS score
FROM db6
WHERE MATCH(body) AGAINST ('" . $all . $none . $any . "' IN BOOLEAN MODE)";
$artm1 = MySQL_query($query);
if(!$artm1) {
echo MySQL_error().'<br>' . $query . '<br>';
}
echo '<b>Matches</b><br>';
if(MySQL_num_rows($artm1) > 0) {
echo '<table>';
echo '<tr><td>Score </td><td>Title </td><td>Body</td></tr>';
while($artm2 = MySQL_fetch_array($artm1)) {
$val = round($artm2['score'], 3);
$val = ($val*100);
echo '<tr><td>' . $val . '</td>';
echo '<td>' . $artm2['poster'] . '</td>';
echo '<td>' . $artm2['body'] . '</td></tr>';
}
echo '</table>';
} else {
echo 'No Results were found in this category.<br>';
}
echo '<br>';
}
?>
En ja dat kan, gewoon meerdere querys maken.
Maar als ik meerdere queries maak, dan zijn de scores toch niet goed in verhouding tot elkaar? Kan ik niet met mysql zoeken in meerdere tabellen in 1 query?
Laat maar ik heb alles in 1 tabel gezet werkt ook :P