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 > [PHP] ใช้ foreach แล้วไม่ทำงาน สั่งให้พิมพ์ array ออกมาแสดงผลโดยข้อมูลเป็น html แล้วใช้งานไม่ได้



 

[PHP] ใช้ foreach แล้วไม่ทำงาน สั่งให้พิมพ์ array ออกมาแสดงผลโดยข้อมูลเป็น html แล้วใช้งานไม่ได้

 



Topic : 104773



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



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




ไม่ทราบว่าท่านใดรู้บ้างครับว่ามันเกิดจากอะไรหน่ะครับ

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\mc\mc\index.php on line 68
Warning: Invalid argument supplied for foreach() in C:\AppServ\www\mc\mc\index.php on line 73


ตัวแปรแสดงผลผ่าน print_r
$story_small_true = Array ( [0] => <div class="panels" style="max-width: 340px; padding: 8px 0;"> <p><iframe frameborder="0" scrolling="no" src="http://27.254.65.73/web/status.php" width="300"></iframe></p> <br /></div><br /> )
$story_big_true = Array ( [0] => <div class="panels"> <center>ยินดีต้อนรับเข้าสู่เว็บไซต์ทดสอบ</center> <br /></div><br /> [1] => <div class="panels"> <p>[@news_table]</p> <br /></div><br /> )


index.php (Code PHP)
function replacer123($file,$type){
		global $site;
		include_once("plugin/story/story.class.php");
		$template = new Template("theme/".$site['theme']."/".$file);
		$story_class = new plugin_story($id,$p,$site);
		##############################################
		
		$template->set("title", $site['name']);
		$template->set("theme", "../theme/".$site['theme']);
		
		if($type=="container"){
			$pattern_small = $story_class->replacer2("pattern_small.tpl",'container_small');
			$pattern_big = $story_class->replacer2("pattern_big.tpl",'container_big');
			//print_r($pattern['small']);
			//print_r($pattern['big']);
			
			foreach($pattern_small as $k){   //บรรทัดที่ 68
				$story_small_true .= $pattern_small[$k];
			}
			$template->set("pattern_page_small",$story_small_true);
			##############################################
			foreach($pattern_big as $k){    //บรรทัดที่ 73
				$story_big_true .= $pattern_big[$k];
			}
			$template->set("pattern_page_big",$story_big_true);
			
		}
		
		##############################################
		return $template->output();
	}




story.class.php (Code PHP)
<?php
if(!defined('IS_IN_MODULE')) { die("NO DIRECT FILE ACCESS!"); }
class plugin_story {
	
	private $id;
	private $pages;
	private $site;
	
	function __construct($id,$pages,$site=array()){
		$this->id = $id;
		$this->pages = $pages;
		$this->site = $site;
	}
	
	function date_thai($strDate)
	{
		$strYear = date("Y",strtotime($strDate))+543;
		$strMonth= date("n",strtotime($strDate));
		$strDay= date("j",strtotime($strDate));
		$strHour= date("H",strtotime($strDate));
		$strMinute= date("i",strtotime($strDate));
		$strSeconds= date("s",strtotime($strDate));
		$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
		$strMonthThai=$strMonthCut[$strMonth];
		return "$strDay $strMonthThai $strYear เวลา $strHour:$strMinute น.";
	}
	
	function value_news_table(){
		$sql = "SELECT * FROM `phoomin201_mcc`.`attc_news` WHERE path='".$this->id."' ORDER BY date DESC LIMIT 0, 10";
		$num = mysql_num_rows(mysql_query($sql));
		$q = mysql_query($sql);
		$menu_pattern = "";
		while($anc = mysql_fetch_array($q)){
			$template = new Template("theme/".$this->site['theme']."/news/news_pattern.tpl");
			$template->set("id_news", $anc['id']);
			$template->set("subject_news", $anc['sub']);
			
			$by = "โดยคุณ <i><b>".$anc['username']."</b></i> เมื่อ ".$this->date_thai($anc['date']);
			$template->set("by_news", $by);
			
			$template->set("text_news", $anc['text']);
			$template->set("date_news", $this->date_thai($anc['date']));
			
			$menu_pattern.= $template->output();
		}
		return $menu_pattern;
	}
	function replacer_news($file){
		$template = new Template("theme/".$this->site['theme']."/".$file);
		$template->set("news_pattern",$this->value_news_table());
		return $template->output();
	}
	
	function replacer3($file,$value,$key){
		$template = new Template("theme/".$this->site['theme']."/".$file);
		$template->set($key,$value);
		return $template->output();
	}
	function replacer2($file,$type){
		global $story;
		$template = new Template("theme/".$this->site['theme']."/".$file);
		##############################################
		
		$template->set("title", $this->site['name']);
		$template->set("theme", "../theme/".$this->site['theme']);

		if($type=="news"){
			$template->set("news_pattern",$this->value_news_table());
		}elseif($type=="container_big"){
			###################################################################
			$sql1 = "SELECT * FROM `phoomin201_mcc`.`attc_part` WHERE path='".$this->id."'";
			$sql1.= " AND page='".$this->pages."' AND size='big' ORDER BY i ASC";
			$p_big = mysql_query($sql1);
			$n = query_num($sql1);$i=0;
			if($n>0){while($p=mysql_fetch_array($p_big)){
				if($i<$n){
					$code = base64_decode($p['code']);
					$code = str_replace("<?","&#8249;?",$code);
					$code = str_replace("?>","?&#8250;",$code);
					$temp_out = $this->replacer3("pattern_big.tpl",$code,"data");
					$temp_out = htmlspecialchars($temp_out,ENT_QUOTES);
					if(preg_match("/\[\@news_table\]/",$temp_out[$i])){
						$template_news = $this->replacer_news("news/news_table.tpl");
						
						$temp_out = str_replace("[@news_table]",$template_news,$temp_out);
					}
					array_insert($story['big'],$temp_out,$i);
				}$i++;
			}}
			return $story['big'];
			###################################################################
		}elseif($type=="container_small"){
			###################################################################
			$sql2 = "SELECT * FROM `phoomin201_mcc`.`attc_part` WHERE path='".$this->id."'";
			$sql2.= " AND page='".$this->pages."' AND size='small' ORDER BY i ASC";
			$p_sml = mysql_query($sql2);
			$pn_sml = query_num($sql2);$i=0;
			if($pn_sml>0){while($p=mysql_fetch_array($p_sml)){
				if(($i)<($pn_sml)){
					$code = base64_decode($p['code']);
					$code = str_replace("<?","&#8249;?",$code);
					$code = str_replace("?>","?&#8250;",$code);
					$temp_out = $this->replacer3("pattern_small.tpl",$code,"data");
					$temp_out = htmlspecialchars($temp_out,ENT_QUOTES);
					array_insert($story['small'],$temp_out,$i);
				}$i++;
			}}
			return $story['small'];
			###################################################################
		}else{
			return $temp_out;
		}
		##############################################
		
		##############################################
		/*foreach($temp_out as $k => $v){
			$template_output.= $v;
		}*/
		##############################################
		
	}
}
?>


ขอขอบคุณล่วงหน้าสำหรับท่านที่ตอบนะครับ



Tag : PHP, MySQL, CakePHP









ประวัติการแก้ไข
2014-01-19 10:50:23
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-01-19 10:49:30 By : phoomin2012 View : 1391 Reply : 5
 

 

No. 1



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

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

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

จากที่คุณ print_r ออกมา มันไม่มี key นิครับ
ลองแบบนี้หรือยัง
Code (PHP)
			foreach($pattern_small as $k){   //บรรทัดที่ 68
	$story_small_true .= $k;
  }







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-19 11:03:09 By : mangkunzo
 


 

No. 2



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



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


แล้วถ้าจะเพิ่ม key ละครับ จะต้องทำยังไงครับ หรือว่าใช้โค้ดตัวเดิมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-19 11:44:24 By : phoomin2012
 

 

No. 3



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

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

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

ลองรึยัง ?
Code (PHP)
foreach($pattern_small as $k){   //บรรทัดที่ 68
$story_small_true .= $k;
 }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-20 13:18:32 By : mangkunzo
 


 

No. 4



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



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


Warning: Invalid argument supplied for foreach() in C:\AppServ\www\mc\mc\index.php on line 68

Warning: Invalid argument supplied for foreach() in C:\AppServ\www\mc\mc\index.php on line 73

เหมือนเดิมครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-01-24 15:18:47 By : phoomin2012
 


 

No. 5

Guest


ต้องการหารายได้แต่ละเดือนเรียงกันออกมา พร้อมกับสรุปยอดทุกเดือน
<!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>
<p><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="right" valign="top"><input type="button" name="button" id="button" value="พิมพ์เอกสาร" onclick="print();">
<style type="text/css" media="print">
input{
display:none;
}
</style> </td>
</tr>
</table>
</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">โรงงานผลิตน้ำดื่ม เมอร์รี่</td>
</tr>
<tr>
<td align="center">13 หมู่ 3 ตำบลจอบึง อำเภอจอมบึง จังหวัดราชบุรี 70150</td>
</tr>
<tr>
<td align="center">โทรศัพท์ 081 420 9598 E-mail [email protected]</td>
</tr>
</table>
<?
include ("connectb.php");
mysql_connect($hostname,$user,$password) or die("ติดต่อฐานข้อมูลไม่ได้");
mysql_select_db($dbname) or die("เลือกฐานข้อมูลไม่ได้");
mysql_query("SET NAMES UTF8");

$month=array(1=>'มกราคม',2=>'กุมภาพันธ์',3=>'มีนาคม',4=>'เมษายน',5=>'พฤษภาคม',6=>'มิถุนายน',
7=>'กรกฎาคม',8=>'สิงหาคม',9=>'กันยายน',10=>'ตุลาคม',11=>'พฤศจิกายน',12=>'ธันวาคม');

$sql="SELECT orderpro.total_orderpro, detail_orderpro.num_orderpro FROM orderpro
INNER JOIN detail_orderpro ON detail_orderpro.id_orderpro = detail_orderpro.id_orderpro
ORDER BY orderpro.id_orderpro";
?>
<?
$sum = "SELECT sum(total_orderpro) FROM orderpro WHERE date_orderpro(YEAR ,[total_orderpro])=2014";
$query =mysql_query($sum);
//$rs = mysql_fetch_array($query);
$t = ($total_orderpro*$m);
$sum=$sum+$t;

$sum = 0;
{
$total_orderpro = $rs['total_orderpro'];
$num_orderpro=$rs['num_orderpro'];
//$totalamount = $totalamount * (1 + $taxrate);
$total_orderpro = $total_orderpro * $num_orderpr;
$sum = $total_orderpro;
}
?>

<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td align="center"><h3>รายงานสรุปยอดขายประจำปี<? echo $yy=date('Y')+543; ?></h3></td>
<td>&nbsp;</td>
</tr>
</table>
</div>
<div align="center"></div>
<tr>
<td align="center"><table width="450" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td width="426" align="center" bgcolor="#CCCCCC"><strong>เดือน</strong></td>
<td width="214" align="center" bgcolor="#CCCCCC"><strong>สรุปยอดขาย</strong></td>
</tr>
<?
$sum="SELECT SUM(total_orderpeo)FROM orderpro";
$total_orderpro=0;
foreach($month as $sum => $m){
$total_orderpro=$total_orderpeo*$sum;
$sum+=$total_orderpro;
?>
<tr>
<td align="center"><?=$m?></td>
<td align="center"><b><? echo $sum ;?></b></td>
</tr>
<? } ?>
<tr>
<td align="right" bgcolor="#CCCCCC"><strong>รายได้รวมทั้งหมด</strong>
</td>
<td align="center" bgcolor="#CCCCCC"><b><? echo $total_orderpro;?></b></td></tr>
</table></td>
</tr>
</table>
<? mysql_close();?>
</body>
</html>
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-02-02 12:50:08 By : na
 

   

ค้นหาข้อมูล


   
 

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