-1

my code to get data

$db = mysql_connect("localhost","root","","news");
   mysql_query("set names 'utf8'");   
      $result = mysql_query($db, "SELECT * FROM  news_list order by id LIMIT 0,4");
    while ($row = mysqli_fetch_array($result))
            { ?>
    <li>
            <a href="#?id=<?php echo $row['id']; ?>" class="">
                <div class="">
                    <img width="64" height="64" src="<?php echo $row['images']; ?>" class="" alt="" itemprop="image" />   </div>
                <div class="">
                  <?php echo substr($row['description'], 0, 50); ?>  తెలుగు     </div>
            </a>
    </li>

                    <?php  } ?>

in this just i need to add set character set utf8

user2226832
  • 3
  • 1
  • 7
  • FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Mar 20 '18 at 12:14
  • 1
    There's no code here that actually attempts to insert into the database – John Conde Mar 20 '18 at 12:14
  • You're mixing APIs which also won't work – John Conde Mar 20 '18 at 12:15

1 Answers1

-1
You can try instead 

$db = mysql_connect("localhost","root","","news");
mysql_set_charset('utf8',$db); 
      $result = mysql_query($db, "SELECT * FROM  news_list order by id LIMIT 0,4");
    while ($row = mysqli_fetch_array($result))
            { ?>
    <li>
            <a href="#?id=<?php echo $row['id']; ?>" class="">
                <div class="">
                    <img width="64" height="64" src="<?php echo $row['images']; ?>" class="" alt="" itemprop="image" />   </div>
                <div class="">
                  <?php echo substr($row['description'], 0, 50); ?>  
    </div>
            </a>
    </li>

                    <?php  } ?>
  • Code dumps do not make for good answers. You should explain *how* and *why* this solves their problem. I recommend reading, "[How do I write a good answer?"](http://stackoverflow.com/help/how-to-answer) – John Conde Mar 20 '18 at 12:41
  • FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Mar 20 '18 at 12:41
  • This code won't work because it mixes mysql APIs. Also, it doesn't address the "insert" issue since there is no actual insert being attempted. – John Conde Mar 20 '18 at 12:41