1

I've trying to put alt text on images but seems to me that doesn't work. Here is how I try

// get the info from the db
$sql = "SELECT name, caption, alt FROM images order by id desc LIMIT $offset, $rowsperpage";
  $result = mysqli_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

   // while there are rows to be fetched...
  while ($list = mysqli_fetch_assoc($result)) {
   // echo data

  echo "<img src=\"upload/".$list['name']."\" alt=\"".$list['alt']."\" /></a>";
  echo $list['caption']; 

With image and caption everything is fine. But in the html of the page I didn't see alt text.

update: var_dump($list)

array (size=3) 'name' => string '3ce08e141493823aeeded14f5dda6573.jpg' (length=36)  
'caption' => string 'image 1' (length=14) 
'alt' => string 'testing alt text 2' (length=18)
Goro
  • 499
  • 1
  • 13
  • 31

3 Answers3

4

You will need to use title because the alt text will be shown in place of the image, any time the image isn't available. title will be shown as a tooltip on :hover for any browsers that support that functionality.

Howli
  • 12,291
  • 19
  • 47
  • 72
1

Make use of the title attribute instead of alt. I wonder why there is a trailing </a> tag on your echo.

The right way...

echo "<img src=upload/".$list['name']." title=".$list['alt']."/>";

Why should I use title attribute ?

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

Try this:

Pl check $list['alt'] is not empty & also set title value, so that you can test properly ...

-- Thanks

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27