473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

hi me again, How do I limit the amount of chars i get from a query.

12
Hi,

How do I limit the amount of charcters in a query result.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT username,cat,comment,photo,userid,rating,date
the $row[comment] result is sometimes very big and I only want to get the first 100 or so characters.

Thanks very much

syb.
Jan 7 '07 #1
6 1351
ronverdonk
4,258 Expert 4TB
Hi,

How do I limit the amount of charcters in a query result.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT username,cat,comment,photo,userid,rating,date
the $row[comment] result is sometimes very big and I only want to get the first 100 or so characters.

Thanks very much

syb.
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT username,cat,SUBSTR(comment,1,100),photo,userid,rating,date
Please note that, contrary to the PHP substr() function, the MySQL substr() function uses 1 as the start of the string.

Ronald :cool:
Jan 7 '07 #2
sybaris
12
Hi,

I used that and it seems to take all of the text away?

Thanks for the help though :)
Jan 8 '07 #3
sybaris
12
Hello again :)

I fixed it using this
Expand|Select|Wrap|Line Numbers
  1. $row[comment] = substr("$row[comment]",0,97);
I had to put the first number to 0 or it got rid of the first letter :) and the comment looked a little odd lol....

One more thing if i may. How would i go about telling it to put
Expand|Select|Wrap|Line Numbers
  1. &nbsp;<a href="http://www.thatsshocking.com/photo/data/$row[cat]/thumbs/$bigimage">More</a>
after $row[comment] If the comment was 97 characters long ?

Thanks once again.

syb
Jan 8 '07 #4
here your are using php substr function to limit the chracter ,and as you can see ronald's reply he ask you you to note
that
contarary to php substr() function mysql substr start position is 1 ,php substr start posistion 0,
so in my opion you should use the mysql substr funtion to bequase it will be faster ,to accomplish that ,so this will help you

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("SELECT username,cat,SUBSTR(comment,1,100) AS comment,photo,userid,ra  ting,date FROM Tablename");
change i mad is only giving a alias to the row comment ( comment ), and your mysql select statment was also incompete so please change ( string, Tablename ) to what ever the table name is , this can be retrived by using this code $row['comment']

as for as your second question is conserned so if statment would do that
Expand|Select|Wrap|Line Numbers
  1. $comment=$row['comment'];
  2. if(strlen($row['comment'])>=97){
  3. $comment.='&nbsp;<a href="http://www.thatsshocking.com/photo/data/$row[cat]/thumbs/$bigimage">More</a>';
  4. }
Jan 8 '07 #5
sybaris
12
Ahh thanks for that, Why would the thing that ronald gave me take all the text away because if i am reading it right it is just doing the same as mine just a little earlier, I am very, very new to this though so i am probably on completely the wrong track :)

(i did feel proud that i managed to get it to do what i wanted though).

So would your thingy be better than mine as i will use yours if it is for the length of comments.

Thanks very much

syb.
Jan 8 '07 #6
sybaris
12

as for as your second question is conserned so if statment would do that
Expand|Select|Wrap|Line Numbers
  1. $comment=$row['comment'];
  2. if(strlen($row['comment'])>=97){
  3. $comment.='&nbsp;<a href="http://www.thatsshocking.com/photo/data/$row[cat]/thumbs/$bigimage">More</a>';
  4. }

That bit does not work, it does not parse the variables any more in the url and it still puts the 'more' link on all of the comments even if they have less than 97 characters :(
Jan 8 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mimisam | last post by:
I have a table with a few hundreds records of products information. I need to retrieve the top 10 records based on the sum of the products quantity. My query is as below: Select *, sum(qty) as...
5
by: Olaf Gschweng | last post by:
We're new into DB2 and have some problem with DB2 8.1 (?) on a Linux system. We load some big tables of a DB2 database from files every day. We do a "DELETE FROM table" for each table and then we...
4
by: Zenon | last post by:
I have a C# application which interacts with an HP UNIX box via PSFTP. I have run in to a problem where the maximum amount of characters I can redirect is 1024. This number leads me to believe...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.