Jump to content

Search bar problem


hello123456789

Recommended Posts

I am trying to write a search bar for a website i was making. Everything seems to go well until it finishes displaying the first search result, even if there are many more search results.

 

Here is the part of the script for displaying the search results:

 


function short_description($des)
{
$final = "";
$final = (substr($des, 0, 200)."...");

echo "<p>".strip_tags($final)."</p>";
}

while($pagerow = mysql_fetch_assoc($pageres)) 	
{
echo "<h2><a href = 'discussion.php?id=".$pagerow['id']."'>".$pagerow['name']."</a></h2>";
echo "Posted on ".date("D jS F Y g.iA", strtotime($pagerow['dateposted']));
short_description($pagerow['body']) or die(mysql_error()); // Executes this line and stops here
}

 

I figured the problem might have to do with the line with "short_description" because I tried adding and echo in the next line but it wouldn't appear, though I am not entirely sure if this is the source of the problem.

 

Any help would be greatly appreciated. Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/136458-search-bar-problem/
Share on other sites

sorry i dont get this;

 

short_description($pagerow['body']) or die(mysql_error()); // Executes this line and stops here

 

why are you trying to show a mysql error for the function?

 

i have a feeling the function is returning a value other than 0 so it is considering it as failed.

 

try changing it to

 

short_description($pagerow['body']) or die("error in function");

 

and you will proborably get error in function printed.

 

let me know how it goes

 

 

Link to comment
https://forums.phpfreaks.com/topic/136458-search-bar-problem/#findComment-712280
Share on other sites

There isn't an error in the function.

 

 

x or y means evaluate x, and if it's true continue into the branch.  If it's false, evaluate y and go into the branch if it's true.

 

 

 

The only time a function is considered true is if it returns a value equivalent (in PHP world) to true.  true or 1 pretty much.

 

 

The or doesn't even make sense there, by the way.

 

Just change it to short_description($pagerow['body']);

 

Link to comment
https://forums.phpfreaks.com/topic/136458-search-bar-problem/#findComment-714433
Share on other sites

Archived

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

×
×
  • Create New...

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.