Forum Moderators: coopster

Message Too Old, No Replies

Partial displaying of a row

         

Habtom

10:00 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can I display half of a text selected from a row of a database on a webpage.

$query = "SELECT content FROM container";
$row = mysql_fetch_row(mysql_query($query));

and I want to display half of the content meaning half of $row[0]

Habtom

omoutop

10:09 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what do u mean by "half a row"?

a) if u mean half the colums in table just echo/print/whatever them (either by name or by numeric index)
for exmample : echo $row['id'] or echo $row[0] are the same

b) if u mean half the text in a field, uset strlen to count characters and just echo/print the 1/2 of them

If you mean anything else please update the post

Habtom

10:16 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was actually looking to display portion of the text in a column, could be limited to 100 characters of whatever is stored in the column itself, similar to displaying preview of a news and displaying the full content on another page after the person chooses to display the full news.

Could there be a simple function I can use without counting them?

Habtom

philestine

10:34 am on Mar 2, 2006 (gmt 0)

10+ Year Member



you could just write the input to another row with a charachter limit then just display that!

Habtom

10:36 am on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this works I think. Thanks

jatar_k

6:35 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could also use substr [php.net] to echo only part of the string by specifying the length you want.

coopster

8:02 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Or just grab a SUBSTRING [dev.mysql.com] of the data in your SQL statement. No sense bringing back the whole column if you aren't going to use it.
$query = "SELECT SUBSTRING(content,1,100) FROM container";