Код:
//if we got something through $_POST
if (isset($_POST['search'])) {
// here you would normally include some database connection
include('db_con.php');
//$db = new db();
// never trust what user wrote! We must ALWAYS sanitize user input
$word = mysql_real_escape_string($_POST['search']);
$word = htmlentities($word);
// build your search query to the database
$sql=mysql_query("SELECT pic_name,id FROM pictures WHERE pic_name LIKE '%" . $word . "%' ORDER BY pic_name LIMIT 10");
//$sql = "SELECT pic_name,id FROM pictures WHERE pic_name LIKE '%" . $word . "%' ORDER BY pic_name LIMIT 10";
// get results
while ($row=mysql_fetch_array($sql))
//$row = $db->select_list($sql);
if(count($row)) {
$end_result = '';
foreach($row as $r) {
$result = $r['pic_name'];
// we will use this to bold the search word in result
$bold = '<span class="found">' . $word . '</span>';
$end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>';
}
echo $end_result;
} else {
echo '<li>No results found</li>';
}
}
Search results :
Warning: Illegal string offset 'pic_name' in ...\search.php on line 19
която се пада
Код:
$result = $r['pic_name'];
някакви идеи защо така ?