Hello,
I have a problem with the php code bellow, I tried many times to set UTF-8
but without any success, I don’t thing the problem with my database, because
I check it and it’s utf8-bin, but how can i retrieve the data from it and
display in the php page as utf-8, this is real problem…???
include("config.php");
// database connection info
$conn = mysql_connect($server, $db_user, $db_pass) or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db($database,$conn) or trigger_error("SQL", E_USER_ERROR);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM $table";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 20;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT linkname, link FROM $table order by id desc LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
echo htmlentities(strip_tags($list['linkname'], 'UTF-8')) . " : " . '<a href="http://'. htmlentities(strip_tags($list['link'], 'UTF-8')) .'">'. htmlentities(strip_tags($list['link'], 'UTF-8')) .'</a>' . "<br />";
} // end while