sandy1028 Posted October 1, 2010 Share Posted October 1, 2010 Hi, Help me out in writing a query to count the character '<p>' in the text_val coumn in the table "articles". And select the rows if count of '<p>' is only 2. Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/ Share on other sites More sharing options...
chintansshah Posted October 1, 2010 Share Posted October 1, 2010 use CHAR_LENGTH() function Query = "SELECT * FROM articles WHERE CHAR_LENGTH('<p>') = 2" Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1117864 Share on other sites More sharing options...
sandy1028 Posted October 1, 2010 Author Share Posted October 1, 2010 Column value of text_val will be as below: <p>(08-04) 13:34 PDT Annapolis, Md. (AP) --</p><p>Former vice presidential candidate Sarah Palin is endorsing a largely .</p> Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1117867 Share on other sites More sharing options...
chintansshah Posted October 1, 2010 Share Posted October 1, 2010 So, you want to search a string "<p>" in column? Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1117890 Share on other sites More sharing options...
fenway Posted October 2, 2010 Share Posted October 2, 2010 You're talking about stripping all of the html -- that's a different beast. Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1118373 Share on other sites More sharing options...
sandy1028 Posted October 3, 2010 Author Share Posted October 3, 2010 No.. Not about striping out. I have to count the number of occurrence of string '<p>' in the value and select only rows which has count as 2. Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1118488 Share on other sites More sharing options...
fenway Posted October 5, 2010 Share Posted October 5, 2010 Oh -- well, short of a UDF (and there is a library of these that support regex), the lazy was is simply to compare the length of original string to a string where you've placed all of the occurences of '<p>' with '' (a blank string), and then just divide by the length of your occurrence. Quote Link to comment https://forums.phpfreaks.com/topic/214889-count-the-characters-in-a-column/#findComment-1119253 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.