Jump to content

Recommended Posts

I am having trouble finding info on how to display a partial result from my sql query. I know what I'd like to do is really simple, but my search always results in how to paginate my query results rather than display the partial data with more link. I'd like it to display like this:

 

Story Title - Date Entered

words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here ...more

 

I can display my results just fine, I would just like to place the partial story on my main page like this. If anyone can point me in the right direction so I can read up on it, I'd be greatful.

im not sure how this would be done exactly, out of my depth in php, lol, as id like to know this aswell

 

but its gonna be something like limiting the text variable to a certain amount of words or something, then making a link, that take you to the correct place

 

sorry i cant be of any more help.

Why not try this?:

 

SELECT LEFT(title, 160) FROM myTable WHERE title = "SomeTitle"

 

That will get the first 160 characters from the 'title' column in 'myTable'. If you want the last 160, change left to right. You could even combine them so you can get 80 characters from the left and 80 from the right.

I've solved the problem. For anyone looking to display "x" amount of characters of a query result, the following function works perfectly:

 

Define your $text variable from your query results (in my case "content")

$text=$row['content'];

 

Set the number of characters by defining $length and the trailing characters (...) by defining $tail

function snippet($text,$length=164,$tail="...") { 
$text = trim($text); 
$txtl = strlen($text); 
	if($txtl > $length) { 
		for($i=1;$text[$length-$i]!=" ";$i++) { 
            			if($i == $length) { 
				return substr($text,0,$length) . $tail; 
           			} 
       			} 
        		$text = substr($text,0,$length-$i+1) . $tail; 
    		} 
    		return $text; 
}

 

then to print the limited result:

echo snippet($text);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.