OLD MYSQL.
Hvordan får jeg et count ind i dette.?
- $query = htmlspecialchars($query);
- $query = mysql_real_escape_string($query);
- $raw_results = mysql_query("SELECT * FROM nyheder
- WHERE (`overskrift` LIKE '%".$query."%') OR (`text` LIKE '%".$query."%') OR (`id` LIKE '%".$query."%') ORDER BY `id` DESC") or die(mysql_error());
- if(mysql_num_rows($raw_results) > 0){
- while($results = mysql_fetch_array($raw_results)){
vil have noget COUNT(*) AS `count` ind i det.
Og få resultatet: -> count." resultater.
--
Har nu prøvet således her, men uden det hjælper.
- $min_length = 1;
- if(strlen($query) >= $min_length){
- $query = htmlspecialchars($query);
- $query = mysql_fetch_object(mysql_real_escape_string($query));
-
- $raw_results = mysql_query("SELECT COUNT(*) AS `count` FROM nyheder
- WHERE (`overskrift` LIKE '%".$query."%') ORDER BY `id` DESC");
- echo ("".$raw_results -> count." resultater.");
- if(mysql_num_rows($raw_results) > 0){
- while($results = mysql_fetch_array($raw_results)){
--
Jeg får nu resultater frem med count(*)
Men den fejler et sted. Da den ikke viser resultaterne.
- $min_length = 1;
- if(strlen($query) >= $min_length){
- $query = htmlspecialchars($query);
- $query = mysql_real_escape_string($query);
-
- $raw_results = mysql_fetch_object(mysql_query("SELECT COUNT(*) AS `count` FROM nyheder
- WHERE (`overskrift` LIKE '%".$query."%') ORDER BY `id` DESC"));
- echo "".$raw_results -> count." resultater.";
- if(mysql_num_rows($raw_results) > 0){
- while($results = mysql_fetch_array($raw_results)){
--
Tror jeg nu fik det løst korrekt.- $min_length = 1;
- if(strlen($query) >= $min_length){
- $query = htmlspecialchars($query);
- $query = mysql_real_escape_string($query);
- $raw_results = mysql_query("SELECT overskrift FROM `nyheder`
- WHERE `overskrift` LIKE '%".$query."%'");
- // count(*)
- $count = mysql_fetch_object(mysql_query("SELECT COUNT(*) AS `count` FROM `nyheder`
- WHERE `overskrift` LIKE '%".$query."%' ORDER BY id"));
- if(mysql_num_rows($raw_results) > 0){
- echo "".$count -> count." resultater.";
- while($results = mysql_fetch_array($raw_results)){
Udskriver: Resultat af din søgning
5 resultater.
og viser de 5 resultater korrekt.
Indlæg senest redigeret d. 12.09.2014 18:03 af Bruger #17554