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 > (Table) มีข้อมูล 3 แถว จะเอามาแสดงผลที่ตาราง แต่อยากให้ตารางแสดงผลอยุ่ที่6แถวเสมอ ช่วยแนะนำหน่อยครับ



 

(Table) มีข้อมูล 3 แถว จะเอามาแสดงผลที่ตาราง แต่อยากให้ตารางแสดงผลอยุ่ที่6แถวเสมอ ช่วยแนะนำหน่อยครับ

 



Topic : 129685



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



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




aa
มีข้อมูล 3 แถว จะเอามาแสดงผลที่ตาราง แต่อยากให้ตารางแสดงผลอยุ่ที่6แถวเสมอ ช่วยแนะนำหน่อยครับ

Code (PHP)
<!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" />
<table width="100%" border="1" cellspacing="0"  bordercolor="#999999"class="table table-bordered">
  <tr>
    <td width="40%"	align="center">หน่วยงาน</td>
    <td width="40%" align="center">เลขที่</td>
    <td width="20%" align="center">จำนวนเงิน</td>    
  </tr> 
 <?php
  $line = 6;
  if($line == 0){$line=1;}
  for($i=1;$i<=$line;$i++)  
  {	
  ?>
   <tr> 
    <td width="10%" width="40%" align="center"><?php echo $row_Recordset1['company']; ?></td>
    <td colspan="3" width="40%" align="center"><?php echo $row_Recordset1['autonumber']; ?></td>
    <td colspan="2" width="20%" align="center"><?php echo $row_Recordset1['boxc']; ?></td>
  </tr>
  <?php
  }
  ?>   
   <tr> 
</table>
</html>




Tag : PHP, MySQL









ประวัติการแก้ไข
2017-12-12 11:11:10
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-12-12 10:11:20 By : briztiz View : 805 Reply : 5
 

 

No. 1



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

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

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

ลองเอาไปปรับใช้เองนะครับ จาก ตย.นี้ผมให้ i=3 คือข้อมูล 3 แถวตามคำถามคุณ
Code (PHP)
$i=3;

while($i>0){
	
	for($j=0;$j<6;$j++){
		
		if($i>0){
			echo "<p>data<p>";
			$i--;
			
			$k=$j+1;
		}
	}
	while($k>0){
		echo "<p>data<p>";
		$k--;
	}
	echo "<hr>";
}

unkk






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-13 11:20:50 By : mangkunzo
 


 

No. 2



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



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


เอาโค๊ดที่ทำงานจริงๆ มาลงให้ดูดีกว่า เอาอะไรมาลง โค๊ดมันไม่สัมพันธ์กันเลย
ปกติควรใช้ while ในการแสดงผล คิวรี่ก็ใม่มีมาให้ดู เลยไม่รู้ข้อมูลมันมาได้ยังไง
เอาโค๊ดที่ให้มาไปทดสอบก็คงไม่ได้

ตัวอย่าง เอาไปแก้ไขเอง
Code (PHP)
$rs=$db->query('select .. from .. where ... limit 6');
$line=0;
while($ro=$rs->fetch_object()){
   $line++;
   echo $line.' line<br>'
}
if( $line<6){
   for($line; $line<6; $line++){
      echo 'empty line<br>';
   }
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-13 11:37:18 By : Chaidhanan
 

 

No. 3



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



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


ตอบความคิดเห็นที่ : 2 เขียนโดย : Chaidhanan เมื่อวันที่ 2017-12-13 11:37:18
รายละเอียดของการตอบ ::
ประมาณ นี้ครับ อาจารย์
Code (PHP)
<?php require_once('Connections/certificate.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['no'])) {
  $colname_Recordset1 = $_GET['no'];
}
mysql_select_db($database_certificate, $certificate);
$query_Recordset1 = sprintf("SELECT * FROM main_certificate_ver2 WHERE `no` = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $certificate) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);$colname_Recordset1 = "-1";
if (isset($_GET['autonumber'])) {
  $colname_Recordset1 = $_GET['autonumber'];
}
mysql_select_db($database_certificate, $certificate);
$query_Recordset1 = sprintf("SELECT * FROM main_certificate_ver2 WHERE autonumber = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $certificate) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array(
	"0"=>"",     
    "1"=>"มกราคม",     
    "2"=>"กุมภาพันธ์",     
    "3"=>"มีนาคม",     
    "4"=>"เมษายน",     
    "5"=>"พฤษภาคม",     
    "6"=>"มิถุนายน",      
    "7"=>"กรกฎาคม",     
    "8"=>"สิงหาคม",     
    "9"=>"กันยายน",     
    "10"=>"ตุลาคม",     
    "11"=>"พฤศจิกายน",     
    "12"=>"ธันวาคม"  				
);
function thai_date($time){
	global $thai_day_arr,$thai_month_arr;
	//$thai_date_return="วัน".$thai_day_arr[date("w",$time)];
	$thai_date_return.=	"".date("j",$time);
	$thai_date_return.=" ".$thai_month_arr[date("n",$time)];
	$thai_date_return.=	" ".(date("Y.",$time)+543);
	//$thai_date_return.=	"  ".date("H:i",$time)." น.";
	return $thai_date_return;
}
			$date=$row_Recordset1['datetee'];
			$eng_date=strtotime($date); 
			//echo thai_date($eng_date); 
?>
<!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" />
<title>Untitled Document</title>
</head>
<body>
<div class="font_article"> <center>
<table width="100%" border="0" cellspacing="0" >
  <tr>
     <td width="20%"><?php $row_Recordset1['no']; ?></td>
     <td colspan="9" width="60%" align="center"><font size="+2"><b><?php echo $row_Recordset1['company']; ?></b></font></td>
     <td width="20%" align="right"><b>เลขที่ </b><?php echo $row_Recordset1['autonumber']; ?></td>
  </tr>  
    <tr>
    <td width="20%">&nbsp;</td>
     <td colspan="9" width="60%" align="center"><font size="+2"><b>ใบสำคัญจ่าย</b></font></td>
     <td width="20%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="10" width="70%"><b>จ่าย  </b>  <?php echo $row_Recordset1['show_province']; ?></td>     
    <td colspan="2" width="30%" align="right"><b>วันที่ </b><?php 
	echo thai_date($eng_date);  ?></td>
  </tr>
  <tr>
     <td colspan="10" width="100%"><b>ที่อยู่ </b>   
	 <?php echo $row_Recordset1['A']; ?></span>   <b>เลขประจำตัวผู้เสียภาษี</b>    <?php echo $row_Recordset1['D']; ?></td>     
  </tr>
  <tr>
      <td colspan="12" width="100%">
      <b>ชื่อบัญชี   </b><?php echo $row_Recordset1['E']; ?>
      <b>ธนาคาร   </b><?php echo $row_Recordset1['B']; ?>
      <b>สาขา   </b><?php echo $row_Recordset1['B2']; ?>
      <b>เลขบัญชี   </b><?php echo $row_Recordset1['C']; ?>      
      </td>
  </tr>
  <tr>
     <td colspan="5" width="30%" align="center"><font color="#CCCCCC">สำหรับเจ้าหน้าที่บัญชี</font></td>
     <td colspan="3" width="30%" align="center"><font color="#CCCCCC">สำหรับเจ้าหน้าที่การเงิน</font></td>
    <td width="10%" align="center"></td>
    <td width="10%" align="center"></td>
    <td width="10%" align="center"></td>
    <td width="10%" align="center"></td>
  </tr>
</table>
 <table width="100%" border="1" cellspacing="0"  bordercolor="#999999"class="table table-bordered">
  <tr>   
    <td width="10%" align="center">ชื่อบัญชี</td>
    <td width="10%" colspan="2" align="center">เดบิต</td>
    <td width="10%" colspan="2" align="center">เครดิต</td>
    <td width="10%" align="center">หน่วยงาน</td>
    <td colspan="3" width="40%"align="center">รายการ</td>
    <td colspan="2" width="20%" align="center">จำนวนเงิน</td>    
  </tr> 
  <?
  if (isset($_GET['autonumber'])) {
  $colname_Recordset2 = $_GET['autonumber'];
}
mysql_select_db($database_certificate, $certificate);
$query_Recordset2 = sprintf("SELECT * FROM main_certificate_ver2 WHERE autonumber = %s limit 6", GetSQLValueString($colname_Recordset1, "text"));
$Recordset2 = mysql_query($query_Recordset2, $certificate) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
  ?>  
 <?php $s=0;do { ?><?php
  $line = 0;
  if($line == 0){$line=0;}
  for($i=1;$i<=$line;$i++)  
  {	    
  ?>
   <tr>  
    <td width="10%" align="center">&nbsp;</td>
    <td width="10%" align="center">&nbsp;</td>
    <td width="4%" align="center">&nbsp;</td>
    <td width="10%" align="center">&nbsp;</td>
    <td width="4%" align="center">&nbsp;</td>
    <td width="10%" align="center"><?php echo $row_Recordset2['boxa']; ?></td>
    <td colspan="3"  width="40%"align="center"><?php echo $row_Recordset2['boxb']; ?></td>
    <td colspan="2" width="20%" align="center"><?php echo $row_Recordset2['boxc']; ?></td>
  </tr>
   
  <?php

  }
  ?>
     <?php $s++;} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
   <tr>  
     <td colspan="6" width="50%" align="Left">&nbsp;</td>
    <td  colspan="3"width="20%" align="center">รวมเงิน</td>   
    <td  colspan="2"width="20%" align="center"><?php echo $row_Recordset1['sum1']; ?></td>  
   
  </tr>
   <tr>
     <td colspan="6" width="50%" align="left">
     <? if (($row_Recordset1['checkbox1']=='on')){ ?>
     <input name="checkbox1" type="checkbox" id="checkbox1" checked="checked" />
      <label for="checkbox1"></label>
     <? } else { ?> 
     <input name="checkbox1" type="checkbox" id="checkbox1" />
	 <label for="checkbox1"></label>
	 <? } ?>       
      เงินสด
	</td>
   <td  colspan="3" width="10%" align="center">
   				<? if ($row_Recordset1['select1']=='0'){  ?>  	
  			   อัตราภาษี  0 %		
               <?  } else if($row_Recordset1['select1']=='0.07'){     ?>
     		   อัตราภาษี  7 %
     		   <? } ?>
</td>
  <td  colspan="2"width="20%" align="center"><?php echo $row_Recordset1['sum2']; ?></td>
   </tr>
   <tr>
     <td colspan="6" width="50%" align="left">
      <? if (($row_Recordset1['checkbox2']=='on')){ ?>
     <input name="checkbox2" type="checkbox" id="checkbox2" checked="checked" />
      <label for="checkbox2"></label>
     <? } else { ?> 
     <input name="checkbox2" type="checkbox" id="checkbox2" />
	 <label for="checkbox2"></label>
	 <? } ?>       
     
      เช็คธนาคาร <?php echo $row_Recordset1['select3']; ?>  สาขา................เลขที่....................ลว............</td>
               <td  colspan="3" width="10%" align="center"> 	         
        		<? if ($row_Recordset1['select2']=='0.01'){  ?>  	
  			   หักภาษี ณ ที่จ่าย 1 %
     			<? } else if($row_Recordset1['select2']=='0.02'){     ?>
     		   หักภาษี ณ ที่จ่าย 2 %
               <?  } else if ($row_Recordset1['select2']=='0.03'){     ?>
     		   หักภาษี ณ ที่จ่าย 3 %
               <?  } else if($row_Recordset1['select2']=='0.05'){     ?>
     		   หักภาษี ณ ที่จ่าย 5 %
               <?  } else if($row_Recordset1['select2']=='0.07'){     ?>
     		   หักภาษี ณ ที่จ่าย 7 %
     		   <? } ?>
  				 </td>
     		   <td colspan="2" width="20%" align="center"><font color="#FF0000"><?php echo $row_Recordset1['sum3']; ?></font>
               </td>  </tr>  <tr>
     <td  width="50%" colspan="6" align="center">(<? echo convert($row_Recordset1['sum4']);?>)</td>    
    <td colspan="3" width="30%" align="center">รวมเงินทั้งสิ้น</td>
    <td colspan="2" width="20%" align="center"><?php echo $row_Recordset1['sum4']; ?></td>
    </tr></table>
 </center>
</body>
</DIV>
</html>



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-13 11:55:06 By : briztiz
 


 

No. 4



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



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


mysql_select_db($database_certificate, $certificate);
ทั้งโปรแกรมมีแค่บันทัดเดียวพอแล้ว


การตั้งชื่อตัวแปร ควรให้มันสื่อความหมาย
Code (PHP)
$colname_Recordset1 = "-1";
if (isset($_GET['no'])) {
$colname_Recordset1 = $_GET['no'];
}
mysql_select_db($database_certificate, $certificate);
$query_Recordset1 = sprintf("SELECT * FROM main_certificate_ver2 WHERE `no` = %s", GetSQLValueString($colname_Recordset1, "int"));

ลองแบบข้างล่างน่าจะสื่อได้ดีกว่า
Code (PHP)
$main_no = isset($_GET['no'])? $_GET['no'] : "-1";
$main_qr = sprintf("SELECT * FROM main_certificate_ver2 WHERE `no` = %s", GetSQLValueString($main_no, "int"));


และถามหน่อยครับ ใช้ php version ไหนครับ น่าจะเปลี่ยนไปใช้ mysqli (มายเอสคิวแอลไอ) ได้แล้วนะครับ
มีตัวช่วยเยอะกว่า เขียนง่ายกว่า และถ้าใช้แบบ oop ยิ่งง่ายเข้าไปอีก เขียนก็สั้นกว่ากัน

ส่วนสิ่งที่ต้องการ ก็ลองอ่านโค๊ดตัวอย่างที่ผมเขียนให้ดู จาก คห2 น่าจะประยุกต์ได้ ดูการใช้ตัวแปร

ปล. ลดการใช้ function ที่ไม่จำเป็น เช่น การสร้าง statement ที่เรารู้ว่า field type เป็น ตัวเลขแน่ๆ
Code (PHP)
$main_no = isset($_GET['no'])? $_GET['no']*1 : -1; // คุณ 1 เพื่อขจัดค่าที่ไม่ใช่ตัวเลข
$main_qr = 'SELECT * FROM main_certificate_ver2 WHERE `no` =  '.$main_no; 
// field type ตัวเลข ไม่จำเป็นต้องมี single quote ครอบ



ประวัติการแก้ไข
2017-12-13 13:23:50
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-13 13:15:19 By : Chaidhanan
 


 

No. 5



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



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


ตอบความคิดเห็นที่ : 4 เขียนโดย : Chaidhanan เมื่อวันที่ 2017-12-13 13:15:19
รายละเอียดของการตอบ ::
ขอบคุณครับ ขอนำไปใช่และปรับปรุงครับอาจารย์

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-12-13 15:34:17 By : briztiz
 

   

ค้นหาข้อมูล


   
 

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