rams73
asked on
Select statement, display first 10 words
Hi
I have selected the contents from my database but i want to display only the first 10 words(not charecter)the rest i want to skip, how to do this.........
Sorry i think i have to edit the question again
I have selected a field from the table, but i want to display only the first 10 words.....
Thanks
Rama
I have selected the contents from my database but i want to display only the first 10 words(not charecter)the rest i want to skip, how to do this.........
Sorry i think i have to edit the question again
I have selected a field from the table, but i want to display only the first 10 words.....
Thanks
Rama
THis is better
Write ur query like this
$Query = "Select * from TableName LIMIT 0,10;";
Jimmy
Write ur query like this
$Query = "Select * from TableName LIMIT 0,10;";
Jimmy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can do this within MySQL also, if you want to use proprietary db functions. This means that your code would not be portable to other databases such as Oracle without a little modification of your SQL, but it is still a cool feature nonetheless...
***** FROM MYSQL MANUAL*****
SUBSTRING_INDEX(str,delim, count)
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned:
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
This function is multi-byte safe.
************************** ***
You can find this function documented at: http://www.mysql.com/doc/S/t/String_functions.html
In your case, the delimiter would be a " " (space), since you want words returned. You query would probably look something like this:
SELECT SUBSTRING_INDEX(field_name _here, ' ', 11) FROM table_name WHERE some_field = 'some_value';
Change "field_name_here" to the field you want the 10 words returned from. Notice that I used 11 instead of 10 in the function... this is because MySQL will (or is supposed to) return everything before it reaches the 11th occurrence of the delimiter specified, which will result in 10 words being returned since the 11th "space" is the boundary of the 10th word.
Good luck...
Barry
***** FROM MYSQL MANUAL*****
SUBSTRING_INDEX(str,delim,
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned:
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
This function is multi-byte safe.
**************************
You can find this function documented at: http://www.mysql.com/doc/S/t/String_functions.html
In your case, the delimiter would be a " " (space), since you want words returned. You query would probably look something like this:
SELECT SUBSTRING_INDEX(field_name
Change "field_name_here" to the field you want the 10 words returned from. Notice that I used 11 instead of 10 in the function... this is because MySQL will (or is supposed to) return everything before it reaches the 11th occurrence of the delimiter specified, which will result in 10 words being returned since the 11th "space" is the boundary of the 10th word.
Good luck...
Barry
rams73,
You have a number of questions have been open for some time, and our records show you logged in quite recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20089048
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20105452
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20182718
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20214594
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20245122
Thanks,
Netminder
Community Support Moderator
Experts Exchange
You have a number of questions have been open for some time, and our records show you logged in quite recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20089048
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20105452
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20182718
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20214594
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20245122
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
$dbconnect = mysql_connect("localhost",
$Query = "Select * from TableName;";
$result=mysql_db_query("db
$row=mysql_fetch_row($resu
for($i=0;$i<10;$i++)
{
print("$row[$i]<br>");
}
The above is based on each record containing one field. If you let me know how many fiels in a record and which one contains the information to display I will rewrite the short script for you.