Hello all,
I have created a script that queries my MySQL database and gets a certain row, then echoes out:
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = mysqli_fetch_array($result))
{
echo "<li><a href=\"#\">";
echo $row['col_5'];
echo "</li>";
}
I would like to check to see if each of the row outputs has a string that is more than 13 characters, and if so, strip it down to 13 and add "..." to the end of the string. I did some research and added a line of code, but it still outputs the long string. Any ideas on where I went wrong?
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = mysqli_fetch_array($result))
{
$row = (strlen($row) > 13) ? substr($row,0,10).'...' : $row; // ADDED THIS LINE
echo "<li><a href=\"#\">";
echo $row['col_5'];
echo "</li>";
}