zoek resultaat weergeven waar het gezochte woord staat
Ik ben weer eens gedoken in mijn kleine project. Je kan in dit opzet een woord ingeven met betekenis etc etc. Nu kan ik een woord opzoeken of deze al bestaat en dat werkt prima, maar ik zou het leuk vinden om te weten op welke pagina deze te vinden is of een link van hier kun je hem vinden. Per pagina zie je 10 woorden met daar achter de betekenis en het gebruik van dat woord.
Kan iemand mij een beetje op weg helpen.
Alvast mijn dank..
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
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
<?php
include('./include/connect.php');
$link = mysqli_connect($db_host, $db_username, $db_pass) or die ("Could not connect to database");
mysqli_select_db($link, $db_name) or die ("Check your database");
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length) { // if query length is more or equal minimum length then
$query = mysqli_real_escape_string($link, $query);
// makes sure nobody uses SQL injection
$query = htmlentities($query);
// changes characters used in html to their equivalents, for example: < to >
$raw_results = mysqli_query($link, "SELECT * FROM wotd_id WHERE (`word` LIKE '%".$query."%') OR (`meaning` LIKE '%".$query."%')") or die(mysqli_error());
if(mysqli_num_rows($raw_results) > 0) { // if one or more rows are returned do following
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
while($results = mysqli_fetch_assoc($raw_results)) {
// $results = mysqli_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<br /><strong><center>";
echo 'The word "'.$results['word']. '" already exists, please add another one';
echo '<p><h4>The word "'.$results['word']. '" means "'.$results['meaning'].'" </h4></p>';
echo '<p><h4>You can find this word on page "'.$results['ID']. '" </h4></p>';
echo "</strong></center>";
// these are posts results gotten from database(word and meaning) you can also show id etc etc ($results['id'])
}
} else { // if there is no matching rows do following
echo "<br /><strong><center>";
echo "No results, you are free to add your word.";
echo "</strong></center>";
}
} else{ // if query length is less than minimum
echo "<br /><strong><center>";
echo "Sorry, I need at least ".$min_length;
echo " Characters or more to search the Database.";
echo "</strong></center>";
}
?>
include('./include/connect.php');
$link = mysqli_connect($db_host, $db_username, $db_pass) or die ("Could not connect to database");
mysqli_select_db($link, $db_name) or die ("Check your database");
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length) { // if query length is more or equal minimum length then
$query = mysqli_real_escape_string($link, $query);
// makes sure nobody uses SQL injection
$query = htmlentities($query);
// changes characters used in html to their equivalents, for example: < to >
$raw_results = mysqli_query($link, "SELECT * FROM wotd_id WHERE (`word` LIKE '%".$query."%') OR (`meaning` LIKE '%".$query."%')") or die(mysqli_error());
if(mysqli_num_rows($raw_results) > 0) { // if one or more rows are returned do following
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
while($results = mysqli_fetch_assoc($raw_results)) {
// $results = mysqli_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<br /><strong><center>";
echo 'The word "'.$results['word']. '" already exists, please add another one';
echo '<p><h4>The word "'.$results['word']. '" means "'.$results['meaning'].'" </h4></p>';
echo '<p><h4>You can find this word on page "'.$results['ID']. '" </h4></p>';
echo "</strong></center>";
// these are posts results gotten from database(word and meaning) you can also show id etc etc ($results['id'])
}
} else { // if there is no matching rows do following
echo "<br /><strong><center>";
echo "No results, you are free to add your word.";
echo "</strong></center>";
}
} else{ // if query length is less than minimum
echo "<br /><strong><center>";
echo "Sorry, I need at least ".$min_length;
echo " Characters or more to search the Database.";
echo "</strong></center>";
}
?>
Er zijn nog geen reacties op dit bericht.