<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aummua Blog &#187; sql</title>
	<atom:link href="http://www.aummua.com/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.aummua.com</link>
	<description>บล๊อกของนายอุ้มสุดหล่อ</description>
	<lastBuildDate>Mon, 17 Jan 2011 19:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>วิธีการดึงข้อมูลจากการบันทึกค่า value ของ Special Ranking</title>
		<link>http://www.aummua.com/how-to-use-query-from-special-ranking/</link>
		<comments>http://www.aummua.com/how-to-use-query-from-special-ranking/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 05:53:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Tip&Trick]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[eathena]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[ragnarok]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.aummua.com/?p=190</guid>
		<description><![CDATA[script PHP ตัวนี้จะเป็นการดึงค่าใน value ที่อยู่ในตาราง global_reg_value ของ Ragnarok ออกมาโดยไม่ต้องทำการติดตั้ง NPC การเก็บค่าต่างๆเพิ่มเลยนอกจาก ต้องติดตั้ง Special Ranking เพียง NPC ตัวเดียว การทำงานของ Special Ranking จะอยู่ในตัวเกมส์ทำหน้าที่เก็บค่า value ลงฐานข้อมูล การเก็บค่าของ NPC ตัวนี้มี 3 ตัวแปร 1. PKPoint คือ PVP คะแนน PVP เมื่อฆ่า 2. MKPoint คือ MVP แต้มที่ได้จากการ ฆ่าบอส 3. EKPoint คือ EMP แต้มที่ได้จากการตีหิน ปกติแล้วถ้าเราสร้าง Query SQL ขึ้นมาแล้วดึง value ออกมาแสดงในรูปแบบ DESC(เรียงมากไปน้อย) จะทำให้ข้อมูลไม่เรียงกัน(สลับมั่วไปหมด) เพราะว่าฟิลด์ [...]]]></description>
			<content:encoded><![CDATA[<div align="center"><img src="http://www.aummua.com/wp-content/uploads/2010/03/demomkpoint.gif" alt="" title="demomkpoint" width="406" height="143" class="alignnone size-full wp-image-194" /></div>
<p>script PHP ตัวนี้จะเป็นการดึงค่าใน value ที่อยู่ในตาราง global_reg_value ของ Ragnarok ออกมาโดยไม่ต้องทำการติดตั้ง NPC การเก็บค่าต่างๆเพิ่มเลยนอกจาก ต้องติดตั้ง <a href="http://www.eathena.in.th/forum/index.php?showtopic=1014">Special Ranking</a> เพียง NPC ตัวเดียว</p>
<p>การทำงานของ <a href="http://www.eathena.in.th/forum/index.php?showtopic=1014">Special Ranking</a> จะอยู่ในตัวเกมส์ทำหน้าที่เก็บค่า value ลงฐานข้อมูล</p>
<p><strong>การเก็บค่าของ NPC ตัวนี้มี 3 ตัวแปร</strong><br />
1. PKPoint คือ PVP คะแนน PVP เมื่อฆ่า<br />
2. MKPoint คือ MVP แต้มที่ได้จากการ ฆ่าบอส<br />
3. EKPoint คือ EMP แต้มที่ได้จากการตีหิน</p>
<p>ปกติแล้วถ้าเราสร้าง Query SQL ขึ้นมาแล้วดึง value ออกมาแสดงในรูปแบบ DESC<em>(เรียงมากไปน้อย)</em> จะทำให้ข้อมูลไม่เรียงกัน<em>(สลับมั่วไปหมด)</em> เพราะว่าฟิลด์ value อยู่ในรูปแบบของ varchar ไม่ใช่ int</p>
<p>มีวิธีแก้ก็คือทำให้ฟิลด์ value กลายเป็นให้ค่าเป็นค่าสัมบูรณ์ด้วย abs()<br />
วิธีใช้ ORDER BY abs(`value`) DESC</p>
<p><strong>การเรียกข้อมูลออกมาแสดงบนเว็บ</strong> <em>ตัวอย่าง PKPoint</em><br />
<code>$result = mysql_query("SELECT * FROM `".$db_game."`.`global_reg_value` WHERE `str` LIKE 'PKPoint' ORDER BY abs(`value`) DESC LIMIT 0 , 10");<br />
	while ( $rd = mysql_fetch_array( $result ) )<br />
	{<br />
		echo "ชื่อ ".cid2namechar($rd['char_id'])." ฆ่าได้ ".number_format($rd['value'])." คน<br />";<br />
	};</code><br />
สังเกตุการแสดงชื่อ จะใช้ฟังชั่น cid2namechar() &#8230; ก็คือการเปลี่ยนจาก char_id เป็น name ในตาราง char</p>
<p>มาดูการสร้างฟังชั่น cid2namechar() ของผมบ้าง.. (ไม่รู้คนอื่นเขียนแบบนี้ป่าวนะ อิอิ)<br />
<code>function cid2namechar($cid) {<br />
global $sql_game;<br />
	$namecid = mysql_fetch_array(mysql_query("SELECT * FROM `".$sql_game."`.`char` WHERE `char_id`=". $cid));<br />
	if( $namecid ) {<br />
		return $namecid['name'];<br />
	} else {<br />
		return 'N/A';<br />
	}<br />
}</code></p>
<p>จบแระ หวังว่าจะมีประโยชน์ อ่ะนะ</p>
<div style='display:none' id="post-refEl-190"></div>]]></content:encoded>
			<wfw:commentRss>http://www.aummua.com/how-to-use-query-from-special-ranking/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
