Jump to content
php.lv forumi

Vārdu kļume.


zintis8789

Recommended Posts

Tādu kodu sen nebiju redzējis :D

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//LV" "http://www.w3.org/TR/html4/loose.dtd">
<head>

               <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
              <meta http-equiv="Content-Language" content="lv" />
</head>
<html>
<b><tr class="sectiontableentry1"><td align="left" height="20">
                                                       <?

                                                       $db_host = 'localhost';
       $db_user = 'userpass';
       $db_name = 'db';

$connection = @mysql_connect($db_host, $db_user, $db_password) or die(mysql_error());
mysql_select_db($db_name, $connection);
mysql_query("SET NAMES UTF8");


                                                       $result1 = mysql_query("SELECT * FROM ipb_topics ORDER BY `ipb_topics`.`last_post` DESC LIMIT 0,1 ");
$row1 = mysql_fetch_assoc($result1);

$title = $row1['title'];
$id = $row1['tid'];
$posts = $row1['posts'];
?>

<b><a href="forum//index.php?/topic/<? echo $id; ?>-<? echo $title; ?>/"><? echo $title; ?></a> 
<?
if($title != ''){
echo "[";
echo $posts;
echo "]";
}
?>
</b></td></tr>
</body>
</html>

Link to comment
Share on other sites

<?php
$db_host = 'localhost';
$db_user = 'xxxx';
$db_password = 'xxx';
$db_name = 'xxx';

@mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name);
mysql_query('SET NAMES utf8');
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo '<pre>' . print_r(mysql_fetch_assoc(mysql_query('SELECT * FROM ipb_topics ORDER BY last_post DESC LIMIT 1')), 1) . '</pre>'; ?>

izveido atsevišķu failu ar šo kodu un izpildi. kādi burti parādās?

Link to comment
Share on other sites

Array

(

[tid] => 3

[title] => PieteikÅ¡anÄs 11. NHL turnÄ«ram.

[description] =>

[state] => open

[posts] => 9

[starter_id] => 7

[start_date] => 1264430287

[last_poster_id] => 6

[last_post] => 1264438994

[icon_id] => 0

[starter_name] => xxx

[last_poster_name] => xxx

[poll_state] => 0

[last_vote] => 0

[views] => 59

[forum_id] => 4

[approved] => 1

[author_mode] => 1

[pinned] => 0

[moved_to] =>

[total_votes] => 0

[topic_hasattach] => 0

[topic_firstpost] => 5

[topic_queuedposts] => 0

[topic_open_time] => 0

[topic_close_time] => 0

[topic_rating_total] => 0

[topic_rating_hits] => 0

[title_seo] => pieteiksanas-11-nhl-turniram

[seo_last_name] =>xxx

[seo_first_name] => xxx

)

Link to comment
Share on other sites

Array

(

[Table] => ipb_topics

[Create Table] => CREATE TABLE `ipb_topics` (

`tid` int(10) NOT NULL auto_increment,

`title` varchar(250) NOT NULL,

`description` varchar(250) default NULL,

`state` varchar(8) default NULL,

`posts` int(10) default NULL,

`starter_id` mediumint(8) NOT NULL default '0',

`start_date` int(10) default NULL,

`last_poster_id` mediumint(8) NOT NULL default '0',

`last_post` int(10) default NULL,

`icon_id` tinyint(2) default NULL,

`starter_name` varchar(255) default NULL,

`last_poster_name` varchar(255) default NULL,

`poll_state` varchar(8) default NULL,

`last_vote` int(10) default NULL,

`views` int(10) default NULL,

`forum_id` smallint(5) NOT NULL default '0',

`approved` tinyint(1) NOT NULL default '0',

`author_mode` tinyint(1) default NULL,

`pinned` tinyint(1) default NULL,

`moved_to` varchar(64) default NULL,

`total_votes` int(5) NOT NULL default '0',

`topic_hasattach` smallint(5) NOT NULL default '0',

`topic_firstpost` int(10) NOT NULL default '0',

`topic_queuedposts` int(10) NOT NULL default '0',

`topic_open_time` int(10) NOT NULL default '0',

`topic_close_time` int(10) NOT NULL default '0',

`topic_rating_total` smallint(5) unsigned NOT NULL default '0',

`topic_rating_hits` smallint(5) unsigned NOT NULL default '0',

`title_seo` varchar(250) NOT NULL default '',

`seo_last_name` varchar(255) NOT NULL default '',

`seo_first_name` varchar(255) NOT NULL default '',

PRIMARY KEY (`tid`),

KEY `topic_firstpost` (`topic_firstpost`),

KEY `last_post` (`forum_id`,`pinned`,`last_post`),

KEY `forum_id` (`forum_id`,`pinned`,`approved`),

KEY `starter_id` (`starter_id`,`forum_id`,`approved`),

KEY `last_post_sorting` (`last_post`,`forum_id`),

FULLTEXT KEY `title` (`title`)

) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8

)

Link to comment
Share on other sites

labi (patiesībā nav labi), tas nozīmē, ka dati datu bāzē ir sačakarēti (2x iekodēti kā utf8), jo kkad agrāk, insertojot datus, netika lietots mysql_query('SET NAMES utf8');

 

pareizi būtu salabot datus (exportēt no db, salabot kodējumu, importēt atpakaļ), bet ja gribi ātru risinājumu - tikai pareizi attēlot to, kas tur šobrīd ir, tad pamēģini tā

 

tgd tajā test failā pēdējo rindiņu aizvieto ar šo. ir normāli lv burti?

<?php
$result1 = mysql_query("SELECT * FROM ipb_topics ORDER BY `ipb_topics`.`last_post` DESC LIMIT 0,1 ");
$row1 = mysql_fetch_assoc($result1);
$title = utf8_decode($row1['title']);
echo $title;
?>

līdzīgi kā dati tika 2x iekodēti, tā arī tagad tiek 2x atkodēti. tāpēc ir funkcija utf8_decode(). bet vispār tā darīt, tas ir 4erez ž

Link to comment
Share on other sites

vsp par ātru pateici paldies ^^

 

pareizāk būtu turpināt darīt nepareizi. izklausās paradoksāli, bet tā ir. ja visu laiku nebija mysql_query('SET NAMES utf8'); tad arī tgd nevajag. savādāk visi jaunie inserti ar mysql_query('SET NAMES utf8'); datu bāzē saglabāsies pareizi (vnlaicīgi būs vecie nepareizie dati un jaunie pareizie dati), un jaunākajiem pēc utf8_decode() lv burtu vietā būs "?"

 

tāpēc es šādā situācijā pārietu uz mysql_query('SET NAMES utf8'); tikai pēc tam, kad būtu salabojis esošos nepareizos datus. noņem nost mysql_query('SET NAMES utf8'); un pats redzēsi, ka utf8_decode() arī vairs nevajag. ja ne, tad uzliec kādreizējo defaulto mysql_query('SET NAMES latin1');

 

kr4 labāk, lai datu bāzē ir konsekventi nepareizi dati, nevis putra ar pareizi/nepareizi nokodētiem datiem, jo pēdējos jau nekādi vairs nevar vnlaicīgi normāli parādīt...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...