Jump to content


Photo

Limiting # of Search Results Charactors


  • Please log in to reply
2 replies to this topic

#1 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 07 March 2006 - 01:31 AM

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

<?
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>";
}
?>





#2 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 07 March 2006 - 02:49 AM

You could use substr() to limit the characters to 50, 100, etc.

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

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

string strip_tags ( string str [, string allowable_tags] )


#3 me1000

me1000
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts

Posted 07 March 2006 - 02:59 AM

Thanks taht did it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users