Gå til innhold

Deler av tekst


Anbefalte innlegg

Videoannonse
Annonse

tja, kan vel ta et forsøk.. kan du kjøre en describe på tabellen og gi meg resultatet?

 

<?php
$conn = mysql_connect('host','user','pass);
mysql_select_db('database',$conn);

$sql = "SELECT * FROM `tabell`";
$result = mysql_query($sql, $conn) or die(mysql_error());

while(false !== ( $rad = mysql_fetch_assoc($result)) )
{
   $content = $rad['content'];
   // Sikkert hente ut mange andre felter også
   echo substr($content, 0, 30); // (og mye annet)
}
mysql_close($conn);
?>

Kan du php eller ikke?

 

EDIT: glemte å bruke substr() ja... fiksa

Endret av hockey500
Lenke til kommentar

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

 

SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)

 

The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are standard SQL syntax. It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning. A negative value may be used for pos in any of the forms of this function.

mysql> SELECT SUBSTRING('Quadratically',5);
        -> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM 4);         -> 'barbar'
mysql> SELECT SUBSTRING('Quadratically',5,6);
        -> 'ratica'        
mysql> SELECT SUBSTRING('Sakila', -3);
        -> 'ila'        
mysql> SELECT SUBSTRING('Sakila', -5, 3);
        -> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM <span style='color:orange'><span style='color:orange'>-4 FOR 2);
        -> 'ki'

This function is multi-byte safe.

 

If len is less than 1, the result is the empty string.

 

SUBSTR() is a synonym for SUBSTRING().

Endret av Nazgul
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...