From the code, I would say that it $data2represents data from 1 row from the database.
So, it should be $data2that contains what you want to display.
Your foreach loop is useless: if you want to display data from 1 row, you can simply use $data2directly.
, $data2, , mysql_fetch_array .
- , :
$result2 = mysql_query("SELECT id,fp_thumb,title FROM media") or die(mysql_error());
while ($data2 = mysql_fetch_array($result2)) {
echo '<li><a href="media.php?id='.$data2['id'].'"><img src="'.$data2['fp_thumb'].'" alt="'.$data2['title'].'" /></a></li>';
}
, , , , - HTML/javascript- - , src title, ; htmlspecialchars
, , :
echo '<li><a href="media.php?id='
. $data2['id']
. '"><img src="'
. htmlspecialchars($data2['fp_thumb'])
. '" alt="'
. htmlspecialchars($data2['title'])
. '" /></a></li>';
( , id , - , )
, :
$data2 - , :
array
'id' => int 152
'title' => string 'this is the title' (length=17)
'fp_thumb' => string 'http://...../' (length=13)
, foreach , $val :
int 152
string 'this is the title' (length=17)
string 'http://...../' (length=13)
( )
.. $val , .
:
$a = 152;
var_dump($a['id']);
null
$a = 'this is the title';
var_dump($a['id']);
:
string 't' (length=1)
.. , .
, :
$a = 'this is the title';
var_dump($a[3]);
:
string 's' (length=1)
. , , :
, , $str [42]. .
:
.
"title" 0; .
, , ""; -)