Jump to content

Archived

This topic is now archived and is closed to further replies.

me1000

Limiting # of Search Results Charactors

Recommended Posts

Ok ive started on a new search, but I dont know how to limit hte # of charactors it returns. Its also showing HTML and I only want it to show plain text, but on the output results of it its showing the whole page, I want to limit the number of characters it returns to like 50 or 100.

heres the code of my page

[code]<?
require_once ("config.php");

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM $sTableName WHERE PAGE_CONTENT LIKE '%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{    

// change page type #'s to words
$page_type = $r["PAGE_TYPE"];
$new_type = "";

if ($page_type == 1) {
$new_type = "Home";
} else if ($page_type == 2) {
$new_type = "People";
} else if ($page_type == 3) {
$new_type = "Things";
} else if ($page_type == 4) {
$new_type = "Ships";
} else if ($page_type == 5) {
$new_type = "Types";
} else if ($page_type == 6) {
$new_type = "Tech";
} else if ($page_type == 7) {
$new_type = "Food";
} else {
$new_type = "Unknown";
}

   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $title=$r["PAGE_TITLE"];
   $message=$r["PAGE_CONTENT"];
   $id=$r["ID"];
   $link = '<a href ="index.php?page_id='.$id.'">'.$new_type.': '.$title.'</a>';
  
   //display the row
   echo "$link <br> $message <br>";
}
?>[/code]



Share this post


Link to post
Share on other sites
You could use substr() to limit the characters to 50, 100, etc.

[code]string substr ( string string, int start [, int length] )[/code]
So, I'm guessing in your case it would be:

[code]$message = substr($message, 0, 50);[/code]
For viewing only text, you could use the strip_tags() function

[code]string strip_tags ( string str [, string allowable_tags] )[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.