How to select only the first line from an raw in mysql
could somebody know how i can displ开发者_StackOverflow中文版ay with echo only the first line from the raw? Code :
$query = mysql_query("SELECT *
FROM articol
WHERE id = '$artid'") or die(mysql_error());
while ($coloana = mysql_fetch_array($query)) {
$continut = $coloana["continut"];
}
<?php echo $continut; ?>
...and its echo me all the field, and i want only first line, or only 180 characters.
select
substring(field_name,1,180) as begin_text,
other_fields_list
from articol where id = '$artid'
Have you tried the keyword 'LIMIT' ?
Just do
$query = mysql_query("SELECT SUBSTRING_INDEX(SUBSTRING(continut, 1, 180), '\n', 1) AS part FROM articol WHERE id = '$artid'") or die(mysql_error());
while ($row = mysql_fetch_array($query)) {
// $continut = $row["part"];
print $row["part"];
}
精彩评论