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 > ให้แสดงผลเฉพาะ นามสกุลไฟล์มที่ต้องการโดยนำข้อมูลจาก MYSQL มาแสดง ครับ



 

ให้แสดงผลเฉพาะ นามสกุลไฟล์มที่ต้องการโดยนำข้อมูลจาก MYSQL มาแสดง ครับ

 



Topic : 083221



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



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




ให้แสดงผลเฉพาะ นามสกุลไฟล์มที่ต้องการโดยนำข้อมูลจาก MYSQL มาแสดง ครับ

คือ ผมมีหน้าแสดงไฟล์ และ ฐานข้อมูล ประมาณนี้

1

2

คืออยากให้มัน แสดงเฉพาะไฟล์ เท่านั้นครับ เช่น หน้า เพจนี้ แสดงเฉพาะ Word เท่านั้น เฉพาะ excel เท่านั้น ประมาณนนี้อ่ะครับ

ได้หรือเปล่าครับ หรือผม ต้องแยก Table ตอน Insert ไปเลย



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-08-31 10:08:18 By : cappuczino View : 1680 Reply : 3
 

 

No. 1



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



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

ได้ครับ คุณต้อง explode นามสกุลออกมาก่อน แล้ว if เอาคับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-31 11:35:38 By : pumin99
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : pumin99 เมื่อวันที่ 2012-08-31 11:35:38
รายละเอียดของการตอบ ::
explode ผมพอเข้าใจ แต่มันจะแยก ในการแสดงข้อมูลยังไงอ่ะครับ งง จริงๆ T_T

คือ ผมดึงข้อมูลมากแสดงแบบนี้

Code (PHP)
<table width="100%" align="center" cellpadding="0" cellspacing="3" class="table">
  <tr>
     <td  colspan="3"  style="white-space:normal"><strong><img src="images/formupload.png" align="absmiddle"/> View Files</strong></td> 
  </tr>
<tr >
			 <td width="5%"   	class="tbl5" style="white-space: nowrap;"><div align="center"><strong>No.</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>File</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Name</strong></div></td>
             <td width="5%"     class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Day</strong></div></td>
             <td width="5%"     class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Time</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Sender</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Details</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Receiver</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Status</strong></div></td>
             
              
             
    </tr>
<?

while($objResult = mysql_fetch_array($objQuery))

?>

<tr>
<td class="tbl7"><div align="center"><?=$objResult["FilesID"];?></div></td>
<td class="tbl7"><center><?= $objResult["Filesname"];?></center></td>
<td class="tbl7"><center><?=$objResult["Name_Filesnew"];?></center></td>
<td class="tbl7"><center><?=$objResult["Date"];?></center></td>
<td class="tbl7"><center><?=$objResult["Time"];?></center></td>
<td class="tbl7"><center><a href="viewmember.php?UserID= <?=$objResult["UserID_Sender"];?>" onClick="js_popup('viewmember.php?UserID= <?=$objResult["UserID_Sender"];?>',783,600); return false;" title="Member"><?=$objResult["Name_Sender"];?></a></center></td>
<td class="tbl7"><center><a href="viewdetails.php?FilesID=<?=$objResult["FilesID"];?>" onClick="js_popup('viewdetails.php?FilesID=<?=$objResult["FilesID"];?>',783,600); return false;" title="">Details</a></center></td>
<td class="tbl7"><center><a href="viewmember.php?UserID= <?=$objResult["UserID_Receiverr"];?>" onClick="js_popup('viewmember.php?UserID= <?=$objResult["UserID_Receiver"];?>',783,600); return false;" title="Member"><?=$objResult["Name"];?></a></center></td>
<td class="tbl7"><center><?=$objResult["Status_Files"];?></center></td>

  </tr>

<?
}
?>
</table>

เอา รูปแสดงไฟล์ออกล่ะ จะได้เป็น แบบนี้

3

ตามในรูปเนี่ย ผมอยากจะให้มัน แสดงเฉพาะ ไฟล์ . pdf เท่านั้น ดึงเฉพาะข้อมูลของไฟล์ .pdf อ่ะครับ

นี้โคดเต็มๆครับ
<?
	session_start();
	if($_SESSION['UserID'] == "")
	{
		echo "Please Login!";
		exit();
	}	

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style_uploadfile.css" type="text/css" />
<title>Untitled Document</title>
<script language="javascript">
function js_popup(theURL,width,height) { //v2.0
leftpos = (screen.availWidth - width) / 2;
    toppos = (screen.availHeight - height) / 2;
  	window.open(theURL, "viewdetails","width=" + width + ",height=" + height + ",left=" + leftpos + ",top=" + toppos);
}
</script>
</head>

<body>

<div id="Form">
  <div id="header">
  </div>
<table width="68%" border="0" align="center" cellspacing="1" >
<tr>
<td>
<?
$objConnect = mysql_connect("localhost","root","6845") or die("Error Connect to Database");
$objDB = mysql_select_db("dc");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT  * FROM files inner join member WHERE member.UserID = files.UserID_Receiver    ";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");


$Num_Rows = mysql_num_rows($objQuery);

$Per_Page = 15;   // Per Page

$Page = $_GET["Page"];
if(!$_GET["Page"])
{
	$Page=1;
}

$Prev_Page = $Page-1;
$Next_Page = $Page+1;

$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
	$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
	$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
	$Num_Pages =($Num_Rows/$Per_Page)+1;
	$Num_Pages = (int)$Num_Pages;
}

$strSQL .=" order  by FilesID desc LIMIT $Page_Start , $Per_Page";
$objQuery  = mysql_query($strSQL);
if($bg == "#666666") { //ส่วนของการ สลับสี
$bg = "#CCCCCC";
} else {
$bg = "#666666";
}
?>
<table width="100%" align="center" cellpadding="0" cellspacing="3" class="table">
  <tr>
     <td  colspan="3"  style="white-space:normal"><strong><img src="images/formupload.png" align="absmiddle"/> View Files</strong></td> 
  </tr>
<tr >
			 <td width="5%"   	class="tbl5" style="white-space: nowrap;"><div align="center"><strong>No.</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>File</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Name</strong></div></td>
             <td width="5%"     class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Day</strong></div></td>
             <td width="5%"     class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Time</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Sender</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Details</strong></div></td>
             <td width="15%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Receiver</strong></div></td>
             <td width="10%"    class="tbl5" style="white-space: nowrap;"><div align="center"><strong>Status</strong></div></td>
             
              
             
    </tr>
<?
$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
if($i%2==0)
{
$bg = "#CCCCCC";
}
else
{
$bg = "#FFFFFF";
}
	
?>

<tr bgcolor="<?=$bg;?>">
<td class="tbl7"><div align="center"><?=$objResult["FilesID"];?></div></td>
<td class="tbl7"><center>
<?php
$file = $objResult["Filesname"];
$extension = strrchr( $file , '.' );
 
switch( $extension )
{
	case '.jpg':
		echo "<img src='images/icon/JPEG-Image-icon.png'  />";
		break;
	case '.JPG':
		echo "<img src='images/icon/JPEG-Image-icon.png'  />";
		break;	
	case '.pdf':
		echo "<img src='images/icon/pdf-icon.png'  />";
		break;
	case '.png':
		echo "<img src='images/icon/PNG-Image-icon.png'  />";
		break;
	case '.gif':
		echo "<img src='images/icon/GIF-Image-icon.png'  />";
		break;
	case '.doc':
		echo "<img src='images/icon/Office-Word-icon.png'  />";
		break;
	case '.docx':
		echo "<img src='images/icon/Office-Word-icon.png'  />";
		break;	
	case '.xls':
		echo "<img src='images/icon/Office-Excel-icon.png'  />";
		break;
	case '.zip':
		echo "<img src='images/icon/rar-2.png'  />";
		break;
	case '.rar':
		echo "<img src='images/icon/rar-2.png'  />";
		break;
	case '.txt':
		echo "<img src='images/icon/TEXT-Image-icon.png'  />";
		break;					
	default :
		echo 'นามสกุลของไฟล์ไม่อยู่ในรายการตรวจสอบ';		
		
}
?>

</center></td>
<td class="tbl7"><center><?=$objResult["Name_Filesnew"];?></center></td>
<td class="tbl7"><center><?=$objResult["Date"];?></center></td>
<td class="tbl7"><center><?=$objResult["Time"];?></center></td>
<td class="tbl7"><center><a href="viewmember.php?UserID= <?=$objResult["UserID_Sender"];?>" onClick="js_popup('viewmember.php?UserID= <?=$objResult["UserID_Sender"];?>',783,600); return false;" title="Member"><?=$objResult["Name_Sender"];?></a></center></td>
<td class="tbl7"><center><a href="viewdetails.php?FilesID=<?=$objResult["FilesID"];?>" onClick="js_popup('viewdetails.php?FilesID=<?=$objResult["FilesID"];?>',783,600); return false;" title="">Details</a></center></td>
<td class="tbl7"><center><a href="viewmember.php?UserID= <?=$objResult["UserID_Receiverr"];?>" onClick="js_popup('viewmember.php?UserID= <?=$objResult["UserID_Receiver"];?>',783,600); return false;" title="Member"><?=$objResult["Name"];?></a></center></td>
<td class="tbl7"><center><?=$objResult["Status_Files"];?></center></td>

  </tr>

<?
}
?>
</table>

<br>
<div class="table" align="center"> Total <?= $Num_Rows;?> Files <?=$Num_Pages;?> Page :</div>
<?
if($Prev_Page)
{
	echo "  <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}

for($i=1; $i<=$Num_Pages; $i++){
	if($i != $Page)
	{
		
		echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
	}
	else
	{
		echo "<b> $i </b>";
	}
}
if($Page!=$Num_Pages)
{
	echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}

mysql_close($objConnect);

?>
</td>
</tr>
</table>
</body>

</html>



ตามวิธีที่พี่บอก พอมีตัวอย่าง แยกข้อความจากฐานข้อมูลไหมครับ




ประวัติการแก้ไข
2012-08-31 13:13:24
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-31 13:11:57 By : cappuczino
 

 

No. 3



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



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


พี่วิน ช่วยผมหน่อยครับบบบบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-31 14:13:53 By : cappuczino
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ให้แสดงผลเฉพาะ นามสกุลไฟล์มที่ต้องการโดยนำข้อมูลจาก MYSQL มาแสดง ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่