Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > อยากรู้วิธีเรียกใช้ fuction เพื่อแสดงชื่อ จากคีย์ ########%%%%%%%%%%%%%



 

อยากรู้วิธีเรียกใช้ fuction เพื่อแสดงชื่อ จากคีย์ ########%%%%%%%%%%%%%

 



Topic : 047479



โพสกระทู้ ( 29 )
บทความ ( 0 )



สถานะออฟไลน์




เรามี fuction getSationName เพื่อแสดงชื่อ
Code (PHP)
	function getSationName( $station_id ){
		$re = mysql_query(" select station_name from tb_station where station_id = ".$station_id." ");
		$rs = mysql_fetch_assoc( $re );
		return  $rs['station_name'];	
	}



เรามี fuction getResults เพื่อแสดงผลลัพธ์

Code (PHP)
    function getResults($to) { 
        $ourShortestPath = array(); 
        $foo = ''; 
        for ($i = 0; $i < $this -> numberOfNodes; $i++) { 
            if($to !== null && $to !== $i) { 
                continue; 
            } 
            $ourShortestPath[$i] = array(); 
            $endNode = null; 
            $currNode = $i; 
            $ourShortestPath[$i][] = $i; 
            while ($endNode === null || $endNode != $this -> startnode) { 
                $ourShortestPath[$i][] = $this -> previousNode[$currNode]; 
                $endNode = $this -> previousNode[$currNode]; 
                $currNode = $this -> previousNode[$currNode]; 
            } 
            $ourShortestPath[$i] = array_reverse($ourShortestPath[$i]); 
            if ($to === null || $to === $i) { 
            if($this -> distance[$i] >= $this -> infiniteDistance) { 
                $foo .= sprintf("no route from %d to %d. \n",$this -> startnode,$i); 
            } else { 
                $foo .= sprintf(' ต้นทาง %d => ปลายทาง  %d = %d (กิโลเมตร) <br> destinations [%d]: Follow the route to the classes (%s).'."\n" , 
                        $this -> startnode,$i,$this -> distance[$i], 
                        count($ourShortestPath[$i]), 
                        implode('-',$ourShortestPath[$i])); 
            } 
            $foo .= str_repeat('-',20) . "\n"; 
                if ($to === $i) { 
                    break; 
                } 
            } 
        } 
        return $foo; 
    } 
} // end class 


แบบเดิมที่ยังไม่มีชื่อ
the shortest route from class 2 to 20 is :
ต้นทาง 2 => ปลายทาง 20 = 44 (กิโลเมตร) destinations [4]: Follow the route to the classes (2-16-21-20).

แบบใหม่ที่มีชื่อ เราจะเรียกใช้ fuction getSationName ยังไงครับ
the shortest route from class 2 to 20 is :
ต้นทาง 2 => ปลายทาง 20 = 44 (กิโลเมตร) destinations [4]: Follow the route to the classes (สารคาม - กันทร - ยางตลาด - กาฬสิน ).



Tag : PHP, MySQL









ประวัติการแก้ไข
2010-08-22 18:51:00
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-08-22 18:49:43 By : wisan191 View : 816 Reply : 2
 

 

No. 1



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

เดาเอานะ ตรงนี้ครับ

$ourShortestPath[$i] เดาว่าตัวแปรนี้เก็บ array of station id

ในส่วนของ else

ให้เพิ่มบรรทัดนี้ก่อน
$ourShortestPath_name[$i] = array();
foreach ($ourShortestPath as $key => $station_id)
{
$ourShortestPath_name[$i][$key] = getStationName($station_id)
}


แล้วบรรทัด
$foo .= sprintf(' ต้นทาง %d => ปลายทาง %d = %d (กิโลเมตร) <br> destinations [%d]: Follow the route to the classes (%s).'."\n" ,
$this -> startnode,$i,$this -> distance[$i],
count($ourShortestPath[$i]),
implode('-',$ourShortestPath[$i]));

แก้ตรง implode('-',$ourShortestPath[$i])); เป็น implode('-', $ourShortestPath_name[$i]));


เดาเอานะคับ ^^




http://www.pjgunner.com






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-22 19:30:38 By : pjgunner
 


 

No. 2

Guest


ยังม่ายได้อะคราบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-23 00:46:35 By : ไไไ
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากรู้วิธีเรียกใช้ fuction เพื่อแสดงชื่อ จากคีย์ ########%%%%%%%%%%%%%
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่