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 > จะเขียนโค้ดยังไง ให้ดึงข้อมูลจากดาต้าเบสมาแสดงคะ ?



 

จะเขียนโค้ดยังไง ให้ดึงข้อมูลจากดาต้าเบสมาแสดงคะ ?

 



Topic : 062149



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



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




จะเขียนโค้ดยังไงถึงจะถูกคะ ลองเขียนดูแล้ว มันยังไม่ได้
ต้องการจะดึงข้อมูลหมวดหมู่ของกระทู้มาแสดง
ตามภาพค่ะ

หมวดหมู่

อยากให้เมื่อเพิ่มหมวดหมู่ลงในดาต้าเบสแล้ว
หมวดหมู่ที่เพิ่มเข้าไป จะแสดงออกต่อมาเรื่อยๆค่ะ


นี่เป็นโค้ดที่ลองเขียนนะคะ

Code (PHP)
<div id="Layer4">
<div id="Layer5">
  <table width="707" height="79" border="1" class="style9" cellpadding="0" cellspacing="0" bordercolor="#FFFF66" >
    <tr>
      <td height="30" colspan="2" class="style31" bgcolor="#FF6600" ><strong> &nbsp;:: </strong>หมวดหมู่<strong> :: </strong></td>
      <td width="116" class="style31" bgcolor="#FF6600" "><div align="center">จำนวนกระทู้</div></td>
      <td width="40" class="style31" bgcolor="#FF6600" "><div align="center">ลบ</div></td>
    </tr>
    <tr>
	
      
      <td width="115" height="46" bgcolor="#FF9900" b><center>
        <img src="image/kapook-18144-2447.gif" width="40" height="40" />
      </center></td>
     
      <td width="426" bgcolor="#FF9900">
	<?
        $sqlC="select * from  forum  order by forum_id desc";
		$queryC=mysql_db_query($db,$sqlC);
		$rowC=mysql_num_rows($queryC)
		$i=0;
		while( $i < $rowC )
		{	
		$row=mysql_fetch_row($queryC);
		
		$forum_id = $row[forum_id];
		$topic = $row[topic];
		$forum_detail = $row[forum_detail];
		$date_forum = $row[date_forum];
		
	echo "$topic" ;
	echo "$forum_detail"  ;
		$i++
		}
		mysql_close();
		?>
	</td>
      <td width="116" bgcolor="#FF9900">&nbsp;</td>
	  <td width="40" bgcolor="#FF9900">&nbsp;</td>
    </tr>
  </table>
</div>
</div>



มันขึ้นแบบนี้ค่ะ Parse error: syntax error, unexpected T_VARIABLE in C:\AppServ\www\pleng\webboard_admin.php on line 120
บรรทัดที่ 120 คือบรรทัดที่ 22 ค่ะ

ไม่ทราบว่าเขียนผิดตรงไหนคะ รบกวนผู้รู้ช่วยบอกหน่อยค่ะ



Tag : PHP









ประวัติการแก้ไข
2011-06-23 23:58:12
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-06-23 23:56:40 By : nokzaz View : 1109 Reply : 7
 

 

No. 1



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

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

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

<?

// ผมเดาเอาน่ะ ว่าตาราง forum  คุณเก็บ หมวดหมู่ (topic) แบบหลายๆ topic

// เห็นคุณอยากออกมาแบบด้านบน แต่ทำไมคุณ รับค่าออกมาหลายตัวจังครับ งง ???

$sqlC="select * from  forum  group by topic order by forum_id desc"; // เอาเฉพาะ topic ออกมาก่อน
$queryC=mysql_db_query($db,$sqlC);

	while($ObjArray = mysql_fetch_array($queryC))
	{	
	$forum_id = $row[forum_id];
	$topic = $row[topic];
	$forum_detail = $row[forum_detail];
	$date_forum = $row[date_forum];
		
	       $Sql=mysql_query("select *  from forum where topic='$topic'"); // อันนี้ผมเดาเอาน่ะครับ ว่าใน forum คุณมีหลาย topic
       $TopicRows = mysql_num_rows($Sql); // นับจำนวน topic
		?>
           <tr><td width="115" height="46" bgcolor="#FF9900"><center>
              <img src="image/kapook-18144-2447.gif" width="40" height="40" />
             </center></td><td width="426" bgcolor="#FF9900">
			 <?echo $topic; // แสดงชื่อหมวดหมู่?>
			 </td>
			 <td>
			<?echo $TopicRows; //แสดงจำนวนหมวดหมู่?>
			 </td>
			 <td>
			           <a href="#">ลบ</a>
			 </td>
			 </tr>
      <?
		}
		mysql_close();
		?>
</table>









ประวัติการแก้ไข
2011-06-24 00:49:32
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-24 00:49:15 By : mangkunzo
 


 

No. 2



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



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


รันโค้ดยังไม่ผ่านค่ะ มันขึ้นว่า
Parse error: syntax error, unexpected $end in C:\AppServ\www\pleng\webboard_admin.php on line 151
151 คือบรรทัดสุดท้ายเลย


Code (PHP)
<? session_start();
	if($_SESSION['user_id'] == "")
		{
		echo "<script> alert (' please LOGIN !!') ;</script>";
		echo"<meta http-equiv=\"refresh\" content=\"0;url='login.php'\">";
		exit();
		}
	if($_SESSION['status'] != "0")
		{
		echo "<script> alert ('This page for admin only') ;</script>"; 
		echo"<meta http-equiv=\"refresh\" content=\"0;url='login.php'\">";
		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" />





</head>

<div id="Layer3">
  <form id="form1" name="form1" method="post" action="">
  
    <span class="style17">
    <?
		
	include ("connect.php");
	$SQL = "SELECT * FROM member WHERE user_id = '".$_SESSION['user_id']."' ";
	$Query = mysql_query($SQL);
	$Result = mysql_fetch_array($Query);

?>
    </span>
    <div align="center" class="style18">ยินดีต้อนรับ <?=$Result["username"];?> เข้าสู่ระบบค่ะ</div>
  </form>
</div>
<div id="Layer4">
<div id="Layer5">
  <table width="707" height="79" border="1" class="style9" cellpadding="0" cellspacing="0" bordercolor="#FFFF66" >
    <tr>
      <td height="30" colspan="2" class="style31" bgcolor="#FF6600" ><strong> &nbsp;:: </strong>หมวดหมู่<strong> :: </strong></td>
      <td width="116" class="style31" bgcolor="#FF6600" "><div align="center">จำนวนกระทู้</div></td>
      <td width="40" class="style31" bgcolor="#FF6600" "><div align="center">ลบ</div></td>
    </tr>
    <tr>
	<?
        $sqlC="select * from  forum group by topic order by forum_id desc";
		$queryC=mysql_db_query($db,$sqlC);
		while($ObjArray=mysql_fetch_array($queryC))
			{			
		$forum_id = $row[forum_id];
		$topic = $row[topic];
		$forum_detail = $row[forum_detail];
		$date_forum = $row[date_forum];
		
		$Sql=mysql_query("select *  from forum where topic='$topic'");
		$TopicRows = mysql_num_rows($Sql); 
		?> 
      
      <td width="115" height="46" bgcolor="#FF9900" b><center>
        <img src="image/kapook-18144-2447.gif" width="40" height="40" />
      </center></td>
     
      <td width="426" bgcolor="#FF9900"><? echo "$topic" ?>	<? echo "$forum_detail" ?></td>
      <td width="116" bgcolor="#FF9900">&nbsp; </td>
	  <td width="40" bgcolor="#FF9900">&nbsp;</td>
    </tr>
  </table>
</div>
</div>

<?
include ("HD_ADMIN.php");
?>


</center>


</html>



ประวัติการแก้ไข
2011-06-24 10:35:05
2011-06-24 10:41:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-24 10:34:04 By : nokzaz
 

 

No. 3



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



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


ตอนนี้รันผ่านแล้วค่ะ แต่ว่า ก็ยังไม่แสดงหมวดหมู่ตามที่ต้องการ
ทำยังไงดีคะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-24 10:39:03 By : nokzaz
 


 

No. 4



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



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


รบกวนผู้รู้ด้วยนะคะ แก้มานานแล้ว TT
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-24 11:02:48 By : nokzaz
 


 

No. 5



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

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

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

ถ้าจะแสดงตามรูปที่แนบมา ผมว่า ผมทำถูกแล้วน่ะครับ
หรือว่าอยากได้ เอ้าพุทแบบไหนครับ เอาตัวอย่างคร่าวๆมาดูทีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-28 11:26:18 By : mangkunzo
 


 

No. 6

Guest


<?
02.
03.//
04.
05.//
06.
07.$sqlC="select * from forum group by topic order by forum_id desc"; // เอาเฉพาะ topic ออกมาก่อน
08.$queryC=mysql_select_db($db);
09.
10.while($ObjArray = mysql_fetch_array($queryC))
11.{
12.$forum_id = $ObjArray[forum_id];
13.$topic = $ObjArray[topic];
14.$forum_detail = $ObjArray[forum_detail];
15.$date_forum = $ObjArray[date_forum];
16.
17.$Sql=mysql_query("select * from forum where topic='$topic'"); // อันนี้ผมเดาเอาน่ะครับ ว่าใน forum คุณมีหลาย topic
18.$TopicRows = mysql_num_rows($Sql); // นับจำนวน topic
19.?>
20.<tr><td width="115" height="46" bgcolor="#FF9900"><center>
21.<img src="image/kapook-18144-2447.gif" width="40" height="40" />
22.</center></td><td width="426" bgcolor="#FF9900">
23.<?echo $topic; // แสดงชื่อหมวดหมู่?>
24.</td>
25.<td>
26.<?echo $TopicRows; //แสดงจำนวนหมวดหมู่?>
27.</td>
28.<td>
29.<a href="#">ลบ</a>
30.</td>
31.</tr>
32.<?
33.}
34.mysql_close();
35.?>
36.</table>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-05 11:00:02 By : คนผ่านมา
 


 

No. 7



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



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


ลองปรับจากความเห็นที่ 2 ตามความน่าจะเป็นไปได้ครับ ไม่รู้ได้ป่าว

<? session_start();
if($_SESSION['user_id'] == "")
{
echo "<script> alert (' please LOGIN !!') ;</script>";
echo"<meta http-equiv=\"refresh\" content=\"0;url='login.php'\">";
exit();
}
if($_SESSION['status'] != "0")
{
echo "<script> alert ('This page for admin only') ;</script>";
echo"<meta http-equiv=\"refresh\" content=\"0;url='login.php'\">";
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" />





</head>

<div id="Layer3">
<form id="form1" name="form1" method="post" action="">

<span class="style17">
<?

include ("connect.php");
$SQL = "SELECT * FROM member WHERE user_id = '".$_SESSION['user_id']."' ";
$Query = mysql_query($SQL);
$Result = mysql_fetch_array($Query);

?>
</span>
<div align="center" class="style18">ยินดีต้อนรับ <?=$Result["username"];?> เข้าสู่ระบบค่ะ</div>
</form>
</div>
<div id="Layer4">
<div id="Layer5">
<table width="707" height="79" border="1" class="style9" cellpadding="0" cellspacing="0" bordercolor="#FFFF66" >
<tr>
<td height="30" colspan="2" class="style31" bgcolor="#FF6600" ><strong> &nbsp;:: </strong>หมวดหมู่<strong> :: </strong></td>
<td width="116" class="style31" bgcolor="#FF6600" "><div align="center">จำนวนกระทู้</div></td>
<td width="40" class="style31" bgcolor="#FF6600" "><div align="center">ลบ</div></td>
</tr>

<?
$sqlC="select * from forum group by topic order by forum_id desc";
$queryC=mysql_db_query($db,$sqlC);
while($ObjArray = mysql_fetch_array($queryC))
{
$forum_id = $ObjArray[forum_id];
$topic = $ObjArray[topic];
$forum_detail = $ObjArray[forum_detail];
$date_forum = $ObjArray[date_forum];

$Sql=mysql_query("select * from forum where topic='$topic'");
$TopicRows = mysql_num_rows($Sql);

?>
<tr>
<td width="115" height="46" bgcolor="#FF9900" b><center><img src="image/kapook-18144-2447.gif" width="40" height="40" /></center></td>
<td width="426" bgcolor="#FF9900"><? echo "$topic" ?> <? echo "$forum_detail" ?></td>
<td width="116" bgcolor="#FF9900">&nbsp; </td>
<td width="40" bgcolor="#FF9900">&nbsp;</td>

</tr>
<?
}
?>
</table>
</div>
</div>

<?
include ("HD_ADMIN.php");
?>
</center>
</html>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-11-05 11:24:09 By : tongkamlekdee
 

   

ค้นหาข้อมูล


   
 

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