ljaii Posted July 3, 2007 Share Posted July 3, 2007 Just a quick query... How do I retrieve only the first couple of words from a field? I have made a news script but don't want to display the entire content of the news article just the first 10 words or so as a brief intro. Many Thanks, lj Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/ Share on other sites More sharing options...
Wildbug Posted July 3, 2007 Share Posted July 3, 2007 SELECT LEFT(50,columnname); Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288762 Share on other sites More sharing options...
ljaii Posted July 3, 2007 Author Share Posted July 3, 2007 Got it to work with SELECT LEFT(columnname,50); Had to change it round but works great thanks Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288807 Share on other sites More sharing options...
Wildbug Posted July 3, 2007 Share Posted July 3, 2007 Oops :-) Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288810 Share on other sites More sharing options...
ljaii Posted July 3, 2007 Author Share Posted July 3, 2007 It works for one query but not for my search query. I currently have this code: $query = "SELECT (LEFT(content,100)), title, date, id FROM news WHERE content LIKE \"%$variable%\" or title LIKE \"%$variable%\" ORDER BY title"; which throws up the error: "Notice: Undefined index: content in..." Help! Thanks, lj Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288844 Share on other sites More sharing options...
Illusion Posted July 3, 2007 Share Posted July 3, 2007 Can u post the full error message. Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288861 Share on other sites More sharing options...
ljaii Posted July 3, 2007 Author Share Posted July 3, 2007 Notice: Undefined index: content in /public_html/****/search.php on line 107 Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288877 Share on other sites More sharing options...
Illusion Posted July 3, 2007 Share Posted July 3, 2007 It seems there is nothing wrong with your query, try this $query = "SELECT LEFT(content,100), title, date, id FROM news WHERE content LIKE '%".$variable."%' or title LIKE '%".$variable."%' ORDER BY title"; check ur php code first. Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288888 Share on other sites More sharing options...
ljaii Posted July 3, 2007 Author Share Posted July 3, 2007 Thanks, but didnt resolve it. It seems it doesnt take the content variable when I add the (LEFT(content,100)) part. Don't know why it doesnt take this when it takes it without the added bit. Confusion. /quit ;p Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288899 Share on other sites More sharing options...
skali Posted July 3, 2007 Share Posted July 3, 2007 Notice: Undefined index, this notice appears when you are trying to access an index in an array that does not exists Use this: $query = "SELECT LEFT(content,100) as content, title, date, id FROM news WHERE content LIKE '%".$variable."%' or title LIKE '%".$variable."%' ORDER BY title"; Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-288904 Share on other sites More sharing options...
ljaii Posted July 4, 2007 Author Share Posted July 4, 2007 Awesome, cheers! Quote Link to comment https://forums.phpfreaks.com/topic/58239-solved-selecting-only-first-couple-of-words-from-a-field/#findComment-289450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.