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 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); 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 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 :-) 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 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. 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 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. 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 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"; 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! 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
Archived
This topic is now archived and is closed to further replies.